从"play dist"开始shell脚本;无法在JAR文件中找到logger.xml [英] start shell script from "play dist" fails to locate logger.xml in JAR file
问题描述
我是Play 2.1的新手,正在尝试找出将Play部署到我们的ops环境中的最简单方法.
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
将构建一个ZIP文件,其中包含运行我的应用程序所需的所有支持JAR以及启动整个程序的一些启动Shell脚本.像冠军一样工作.
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.
问题在于,与开箱即用的一键通"所有日志/application.log相比,我的应用程序需要更多的细粒度日志记录.在开发人员的框上,我弄清楚了如何创建和配置conf/logger.xml以便按Controller类(实际上是任何类,但暂时保留Controller)执行老式的主题日志记录.当我通过Play控制台运行时,这在我的开发箱上可以正常工作,但是当我通过"play dist"构建我的应用程序并仅使用start shell脚本在应用服务器上启动它时,我从未获得配置该记录器的日志文件生产.我也相信,但是没有这些我不知道的日志,start命令也无法找到我为我的项目配置的Global对象.
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.
查看我的应用程序JAR文件,我可以看到conf/application.conf和conf/logger.xml文件位于JAR中,只是在应用程序启动时不会被加载.
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.
我如何执行启动脚本以从JAR文件加载logger.xml?我真的必须在命令行上使用-D来指定它,还是应该直接将其从应用程序的JAR中加载出来?
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?
推荐答案
我建议编辑生产开始脚本以将以下内容添加到Java命令行:
I recommend editing your production start script to add the following to your java command line:
-Dconfig.resource=/conf/logger.xml
如果在您的类路径中,它将找到记录器配置. (我认为还有一个-Dconfig.file
替代方法).我还建议将配置目录添加到类路径,这样您的play start命令将类似于:
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
通过从类路径中的目录而不是jar文件中获取配置,您就可以对其进行编辑或指定其他版本.
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.
这篇关于从"play dist"开始shell脚本;无法在JAR文件中找到logger.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!