JAR 应用程序的配置
我想像 JAR 文件一样分发我的应用程序并通过外部文件进行配置,因此最终的目录结构将如下所示:
--conf ----log4j.properties ... --lib ----log4j.jar ... --myApp.jar --run.bat
在 run.bat 中,我使用以下命令启动我的应用程序:
java -jar myApp.jar
在 MANIFEST.MF 中,我有类路径条目:
Class-Path: conf/log4j.properties lib/log4j.jar
但是应用程序无法找到其配置文件(但它能够找到库!)。我缺少什么?无论如何,将配置文件外部化到与“主”JAR 相关的文件夹中是一个好习惯吗?
编辑: 我将配置文件外部化的目的是这样可以更轻松地编辑它们。 编辑:配置-> conf(问题描述中的拼写错误)
I want to distribute my application like a JAR file and configurable by external files, so the final directory structure will looks like:
--conf ----log4j.properties ... --lib ----log4j.jar ... --myApp.jar --run.bat
In the run.bat I start my application with:
java -jar myApp.jar
In the MANIFEST.MF I have class-path entry:
Class-Path: conf/log4j.properties lib/log4j.jar
But the application is not able to locate its configuration files (but it is able to locate the libs!). What I am missing? Anyway is it a good practice to externalize configuration files to a folder which are relevant to the 'main' JAR?
EDIT:
My intention to externalize the configuration files is that in this way they can be edited more easily.
EDIT: config -> conf (typo in the description of the issue)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类路径应该是:
The classpath should be:
是否因为您的配置文件位于“conf”目录中并且您的类路径正在寻找“config”目录? :)
Is it because you have your config files in the "conf" directory and your classpath is looking for a "config" directory? :)