views:

32

answers:

1

Hello,

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/application.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?

+2  A: 

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.

tangens
Thanks.! So far I've tried putting "../common" in the manifest classpath as suggested, but it still does not appear to see it. The -jar option doesn't overwrite -D parameters too, does it?
Will
I don't believe that `-D` is ignored here. You could try it by removing your `-jar` parameter, putting your jar into the `-cp` arguments and specifying your main class explicitly. If everything works then, you can go back and try to make the `-jar` parameter work.
tangens
It appears to work if I put the properties file in the same directory as the jar and specify "." in the manifest classpath. It does not work if i specify "../common" though, could this perhaps be a security feature to restrict the classpath to only dirs underneath?
Will
it worked! i had to specify it as ../common/ , it didn't work without the trailing slash
Will