Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass Java System Properties to the JVM when executing "run-app" in Grails 2.3.1

How can I pass Java System Properties to the JVM when executing "run-app" in Grails 2.3.1? When running "grailsw run-app" two JVM are started. The Grails Console and the tomcat container running my Grails Application. I have tried appending them between and in front of the Grails target command. I have a feeling I will need to modify a script.

501 640 622 0 9:39AM ttys000 1:20.20 /Library/Java/Home/bin/java -server -Xmx768M -Xms64M -XX:PermSize=32m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8 ... --conf /Users/hbrien/Software/grails-2.3.1/conf/groovy-starter.conf --classpath run-app

501 661 640 0 9:40AM ttys000 1:50.24 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -Xmx1024M -Xms1024M -XX:MaxPermSize=256m -Dgrails.fork.active=true -Dgrails.build.execution.context=/private/var/folder -Djdk.reflect.allowGetCallerClass=true -Dspringloaded=profile=grails;cacheDir=/Users/hbrien/.grails/2.3.1 org.grails.plugins.tomcat.fork.ForkedTomcatServer

like image 946
Hugh Brien Avatar asked Nov 12 '22 19:11

Hugh Brien


1 Answers

I have discovered similar problem in debugging in Eclipse/GGTS. Running project without any grails.project.fork configuration in BuildConfig doesn't fork, but debugging always fork Tomcat.

I think it's side effect of this issue: http://jira.grails.org/browse/GRAILS-9836

Strange is that this issue is marked unresolved, but pull request is merged and it is in actual code base. I wanted to pass some properties to forked Tomcat process and ended up with this ugly code in BuildConfig.groovy:

if (!System.getProperty('grails.fork.active')) {

    def forkedJvmArgs = System.getProperties()
        .findAll { it.key.startsWith('PARAM') }
            .collect { new String("-D${it.key}=${it.value}") }

    println "Passing properties to forked process: $forkedJvmArgs"

    grails.project.fork = [run: [jvmArgs: forkedJvmArgs]]
}
like image 120
mschayna Avatar answered Nov 15 '22 07:11

mschayna