Developing Grails Apps With Jetty, Deploying on JBOSS: The Problem Of Properties Files
Uncle Moe always used to tell us kids to “Never hard code environment specific parameters into the .war or .ear files you use to deploy your applications”. We were hungry back in those days, but we never wanted for good architectural advice! Old Man Moe’s approach is pretty common these days and you can find plenty of good concrete tips on separating out your configuration data from your .wars if you are developing straight-up Spring applications (check out this article for example.) But I’ve been wondering about the best way to keep configuration information nicely factored out as I develop Grails apps on Jetty, with JBoss as the the target for production deployment.
JBoss supports a -P <properties-file> parameter that uses the content of <properties-file> to set an arbitrary collection of system properties. My colleagues and I use this to set system properties such as JDBC connect parameters, and we subsequently reference these properties in Grails configuration files like DataSource.groovy.
We end up with a set up like this:
$HOME/jboss.properties:
....
appFoo.smtp.server=mail.foo.com
appFoo.jdbc.url=jdbc:oracle:thin:@dbxserv:1521:ORA
appFoo.db.username=abc
appFoo.db.password=axbc2dev
DataSource.groovy:
environments {
development {
....
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:mem:testDb"
}
}
production {
dataSource {
dbCreate = "update"
url = System.properties.get("appFoo.jdbc.url")
driverClassName = "oracle.jdbc.OracleDriver"
username = System.properties.get("appFoo.db.username")
password = System.properties.get("appFoo.db.password")
}
}
}
I recently spent a bit of time tinkering with various ways to launch Grails within Jetty such that the properties in $HOME/jboss.properties can be incorporated into the run time environment. When run from maven (using the maven-jetty-plugin) Jetty can be configured to read system properties settings from such a file. This is described in detail here. The upshot is to use the systemPropertiesFile parameter to point to a file that contains the system property settings.
This seemed like a good alternative for me because I generally build my Grails applications via a maven pom (using the grails-maven-plugin.) Unfortunately, when I included the jetty plugin in my pom.xml and tried to run my Grails app using mvn jetty:run I found two major problems: First compliation takes place each time, which makes start up very slow. Second, and this is the real kiss of death for me at the moment, I get “java.lang.OutOfMemoryError: PermGen space” errors even if I run with -XX:MaxPermSize=1024m (as part of my JAVA_OPTS setting.)
So I found myself needing a way outside of Maven to have Jetty read in system property settings from a file. I came up with a provisional solution, which will probably work for you if you use Cygwin or *nix.
In my .bashrc I file I set up the following function :
gatherJettyProps() {
export JETTY_PROPS=
grep '=' $HOME/jboss.properties | \
sed -e's/\(.*\)=\(.*\).*$/-D\1=\2/' > /tmp/jboss.props
for prop in `cat /tmp/jboss.props ` ; do
export JETTY_PROPS="$JETTY_PROPS $prop "
done
}
then I set up this alias to run Grails:
alias grun=" gatherJettyProps ; grails $JETTY_PROPS run-app"
This is clunky (and command shell specific), but it does serve to launch my Grails app via Jetty and allows me to test with the same property settings that I would use in production. If anyone has a way to do this with some command line option to Jetty that is passed through when running grails run-app, I’d love to hear from you.
























No Responses to “Developing Grails Apps With Jetty, Deploying on JBOSS: The Problem Of Properties Files”