从“play dist"启动shell脚本无法在 JAR 文件中找到 logger.xml [英] start shell script from "play dist" fails to locate logger.xml in JAR file

查看:23
本文介绍了从“play dist"启动shell脚本无法在 JAR 文件中找到 logger.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Play 2.1 的新手,正在尝试找出将 Play 部署到我们的运营环境中的最简单方法.最有希望的开箱即用的 Play 2.1 功能是

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 来执行每个控制器类的老式主题日志记录(实际上是任何类,但现在让我们坚持使用控制器).当我通过播放控制台运行时,这在我的开发箱上运行良好,但是当我通过play dist"构建我的应用程序并仅使用启动 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 替代方案).我还建议在您的类路径中添加一个配置目录,这样您的播放开始命令将类似于:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆