开发者

Java: can't load applications.properties

开发者 https://www.devze.com 2023-01-18 05:02 出处:网络
I have a basic executable JAR with manifest.txt containg the MainClass and some other jar dependencies.

I have a basic executable JAR with manifest.txt containg the MainClass and some other jar dependencies.

I wanted to move my config file, "application.properties" outside the jar into a directory where it's easy to configure/maintain. The java code does a simple ResourceBundle.getBundle('application.props') to load it.

I have a directory setup that looks like this:

/bin/run.sh
/lib/stuff.jar
/common/app开发者_StackOverflowlication.properties

My run.sh looks similiar to this:

 TOOLNAME="stuff.jar"
 CLASSPATH="../common"
 java -cp ${CLASSPATH} -Dapplication.props=application  -jar ../lib/${TOOLNAME}.jar &

When I run this, the jar runs, but still seems unable to find the application.properties file.

I'm not sure if this is somehow due to the manifest.txt overriding my -D parameter. Also wondering, is it possible to move the classpath for this "../common" folder into the manifest.txt?


The problem is your parameter -jar. If you specify that, the parameter -cp is ignored.

You can put your classpath into your manifest, the path specified there is relative to the surrounding path of the jar. If you specify ../common there, you will be able to access your application.properties as a resource.

0

精彩评论

暂无评论...
验证码 换一张
取 消