问题
I'm new to Play 2.1 and am trying to figure out the easiest way to deploy Play into our ops environment. The out-of-the-box Play 2.1 capability that holds the most promise is
play dist
Which builds a ZIP file that contains all the supporting JARs to run my app as well as some start shell script which launches the whole thing. Works like a champ.
The problem is that my application requires more fine-grained logging than afforded by the out-of-the-box one-size-fits-all logs/application.log. On my dev box, I figured out how to create and configure conf/logger.xml to perform old-school topic logging per Controller class (any class, actually, but lets stick with the Controllers for now). This works fine on my dev box when I run though the play console, but when I build my application through "play dist" and start it on the app server with just the start shell script, I never get the logfiles that this logger is configured to produce. I also believe, but without those logs I don't know, that the start command also fails to locate the Global object I have configured for my project.
Looking into the JAR file that is my application I can see the conf/application.conf and conf/logger.xml files are in the JAR, they just aren't being loaded as the application fires up.
How do I get the execution of the start script to load the logger.xml from the JAR file? Do I really have to specify it on the commandline with -D or should it just load directly out of the application's JAR?
回答1:
I recommend editing your production start script to add the following to your java command line:
-Dconfig.resource=/conf/logger.xml
That will find the logger config if it's in your classpath. (I think there's also a -Dconfig.file
alternative). I also recommend adding a configuration directory to your classpath, so your play start command will be something like:
MYAPP_HOME=~/myapp
java -cp $MYAPP_HOME:$MYAPP_HOME/lib/* play.core.server.NettyServer $MYAPP_HOME
By getting your config from a directory in your classpath rather than from a jar file, you gain the ability to edit it, or to specify different versions.
来源:https://stackoverflow.com/questions/16906837/start-shell-script-from-play-dist-fails-to-locate-logger-xml-in-jar-file