Resource Bundles outside of JARs

S

success_ny

I would like to package my Java application (executable, not J2EE or
web) in a JAR and not package my resource bundle properties file in a
JAR. My reasoning is as follows: one of the reasons I use resource
bundle as a .properties file is that it makes it easy to make changes
to certain properties dynamically at run-time without recompiling the
application. Especially if the application is in production, any
changes to the JAR would be complicated. So, ideally I would like my
resouce bundle properties file to reside separately from the JAR where
the code is packaged so I can change, say, flag settings (like, enable
debugging at run-time) or make other changes without touching the JAR.
Does it make sense? How do I load Resource Bundle if it just resides on
the file system and is not part of JAR efficiently?

Thank you!
 
O

Oscar kind

I would like to package my Java application (executable, not J2EE or
web) in a JAR and not package my resource bundle properties file in a
JAR.

This is not difficult. Resources don't have to be in a .jar file; they
just have to be in the classpath. Add a Class-Path header to the manifest
for ".", and the resource files may also be located in th same directory
as the .jar file.
 
F

Ferenc Hechler

you can add an entry like
[---]
Class-Path: .
[---]
to the manifest file of your jar and put the property-files in the folder
you started the jar from.
This is equivalent to starting your jar with the option "-classpath .".
 
O

Oscar kind

Ferenc Hechler said:
This is equivalent to starting your jar with the option "-classpath .".

Alas, this is not generally true: when you start a .jar file with the -jar
switch, any classpath settings outside the .jar file are ignored.
 
S

success_ny

So let me make my question specific and clear: if I call my java
program from a command line supplying CLASSPATH like this (on Unix):

CLASSPATH=.:$CLASSPATH:$JARS_HOME:$JARS_HOME/j2ee.jar:MyApp.jar
java -classpath com.blah.MainProgram

Then I can put the myResources.properties file in that same JARS_HOME
directory and call it from the Java like this:

myResourceBundle = ResourceBundle.getBundle("myResources",
Locale.ENGLISH);

That does not work!

Any ideas how to make it work?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top