您的位置:首页 > 大数据 > 人工智能

Grails 改变端口运行

2011-04-29 14:12 113 查看
Changing the Grails Default Server Port
更改Grails默认服务端口

从命令行运行Grails应用程序(例如使用grails run-app)时,默认情况下它将在8080端口上运行。但是有些时候服务器的8080端口已经被其他应用程序占用,这时它将会报错:

Server failed to start: LifecycleException:  Protocol handler initialization failed: java.net.BindException: Address already in use: JVM_Bind<null>:8080


更改Grails应用程序运行端口的方法有几种。


1. 在命令行使用-Dserver.port参数指定运行端口:

grails -Dserver.port=9000 run-app


2. 永久性改变项目的运行端口:
You can change the port for your project so that every time you run the project, it runs on a new port without having to add command line arguments.


To do this, go to the root directory for your project and then change into the grails-app/conf directory. Create a new file called BuildConfig.groovy (or edit the existing file if there is already one there) and add this line to the file:

grails.server.port.http = 9000


The nice thing about this approach is that if you have multiple grails projects you are working on, you can assign them all to a different port and have them running at the same time.


这种方法的优点是可以为多个同时运行的项目分别设置不同的端口。



3. 修改用户的默认设置:
To change the default so that projects always use the 9000 port instead of 8080, go into the .grails directory in your home directory. This is your home directory on your computer, not the grails or grails project home directory. Also note that this directory gets created once you run a grails application. If the directory does not exist, run your grails application and it will get created.

In the .grails directory, create a file called settings.groovy (or edit the existing file if there is one there already) and add the following line:

grails.server.port.http = 9000


With this line added, it will change the default port used by all grails projects on your machine that make use of the default port.


这种方法将使得该用户所运行的Grails应用默认在9000端口上运行。

4. 修改Grails程序的默认设置:
Another solution is to change the default port used by Grails itself. In Grails 1.1 at least, the trick is to modify the $GRAILS_HOME/scripts/_GrailsSettings.groovy file. In it, you will find a reference to the default port (8080). Just change it to whatever you require, and Grails will always run on this new port. The modified entry might look like this:

serverPort = getPropertyValue("server.port", 9000).toInteger()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: