[ale] OT: Java application properties

Jason Day jasonday at worldnet.att.net
Thu Feb 6 16:34:14 EST 2003


On Thu, Feb 06, 2003 at 09:20:31AM -0700, Joe wrote:
> Hi folks,
> 
> Various Java documentation seems to imply that for a given
> Java executable class MyClass, one can create a property
> file with a magic name, such that the JVM will automatically
> read that property file and add the properties therein to
> the System properties, when MyClass's main() is invoked.
> Is this true? If so, what is the required name and location
> of the magic application property file? I'd expect it to
> be something like "MyClass.properties", but I can't seem to
> track down any solid documentation on this (which probably
> means that it's in a totally obvious place I haven't thought
> of looking yet...)

This isn't true to my knowledge, but I have not looked at the specs for
JDK 1.4 very much.

By convention, a properties file for a given class is located in the
same directory as the class (and thus is in the same package) and has
the same name as the class with ".properties" appended.  You still have
to load the properties file, though.
> 
> Or do I have to manually load the property file and call
> System.setProperties()?

Yes, and no.  Look at Properties.load(InputStream).  Also look at
Class.getResourceAsStream(String).

If you follow the convention, you should be able to load the properties
file like this:

Properties props = new Properties();
try {
    String name = getClass().getName() + ".properties";
    props.load (getClass().getResource (name));
    System.setProperties (props);
}
catch (IOException e) {
    // handle error
}

I haven't actually tried to compile this, so please forgive any typos.

> 
> The reason I think it can be handled automatically is that
> some Java standard library elements, such as RMI/IIOP,
> state that certain configuration values have to be
> specified "on the command line (as system properties) or
> in the application property file." The nature of the
> "application property file" is what I'm confusled about.

This is application dependent.  Some applications use standard
properties files which are loaded by the application when it starts.
Some properties files are specified by a spec.  For instance, the JNDI
spec specifies a jndi.properties file that is loaded by the JNDI
provider.

HTH,
Jason
-- 
Jason Day                                       jasonday at
http://jasonday.home.att.net                    worldnet dot att dot net
 
"Of course I'm paranoid, everyone is trying to kill me."
    -- Weyoun-6, Star Trek: Deep Space 9
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list