playframework
playframework copied to clipboard
Passing -Dconfig.resource to start script & runPlay task
Hi, currently the start script & the runPlay
task are passing options like -Dconfig.resource incorrectly to the play server.
Start script generated by this plugin
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %MAIN_OPTS% -classpath "%CLASSPATH%" play.core.server.ProdServerStart %CMD_LINE_ARGS%
Start script generated by sbt play
if "!_TEST_PARAM:~0,2!"=="-D" (
rem test if this was double-quoted property "-Dprop=42"
for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
if not ["%%H"] == [""] (
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
) else if [%2] neq [] (
rem it was a normal property: -Dprop=42 or -Drop="42"
call set _PARAM1=%%1=%%2
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
shift
)
)
) else (
if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%2
shift
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
)
)
shift
goto param_loop
:param_afterloop
set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS!
/* ... */
"%_JAVACMD%" !_JAVA_OPTS! !ACLICKTOGO_OPTS! -cp "%APP_CLASSPATH%" %MAIN_CLASS% !_APP_ARGS!
As you can see, the options starting with -D
are extracted and merged into JAVA_OPTS
before passing to the play server.
Currently, I'm working around this problem by setting JAVA_OPTS="-Dconfig.resource=application.dev.conf"
before running the start script but hopefully some fixes will be made so this plugin behaves the same as sbt-play
I have the same issue, even with the latest build of this plugin. We desperately try to migrate from sbt and this seems to be the last issue we need to solve. Could anybody advice me on how to set the config.resource param or any play application param? Maybe by configuring the dist task? Thanks!
@lovethisshit Here is my workaround. Add the following lines to build.gradle
runPlay {
def config = project.findProperty("config") ?: "application.conf"
forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999', "-Dconfig.resource=${config}"]
}
You can then execute gradle runPlay -Pconfig=application.dev.conf
.
For running the binary produced by stage
task, create a wrapper script like this:
#!/bin/sh
JAVA_OPTS="-Dhttp.port=8077 -Dconfig.resource=application.production.conf" ./build/stage/main/bin/main
This helps a lot, thanks! Just a typo I guess, it only works with gradle runPlay -Dconfig=...
You can also set default JVM options that get embedded in the startup script by adding this snippet to your build:
createMainStartScripts {
defaultJvmOpts = [ '-Dconfig.resource=application.production.conf' ]
}
The main issue is that if you are trying to work in dynamic environments like heroku that give you random ports to bind to - you are doomed. You can't embed the port in any static configs since you only can get it from env var.
The workaround is adding your own custom start script (one generated by sbt or some other) and copying it to bin folder during staging