grails更改端口號

3.0.9版本:

grails run-app --port=9000
server:
     port: 9000
     context-path: '/xxx' #指定程序啓動後的名字。即: http://localhost:9000/xxx   使用'/@info.app.name@' 出來的不是項目名稱。

以下來自於 搜索內容:親測有效果
grails改變端口號:

更改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: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.
這種方法的優點是可以爲多個同時運行的項目分別設置不同的端口。

  1. 修改用戶的默認設置:
    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端口上運行。

  1. 修改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()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章