I have a jar
file with properties
configuration file.
when I run it in Netbeans
everything works as it should.
but when I run it in a cmd
- the properties file is not found.
why?
I have a jar
file with properties
configuration file.
when I run it in Netbeans
everything works as it should.
but when I run it in a cmd
- the properties file is not found.
why?
It depends on how you're loading your properties file. Consider to load your properties with the help of:
InputStream in = getClass().getResourceAsStream("/log4j.properties");
and then use Properties.load(in)
This should handle the situation when the properties file physically resides in the jar Good Luck!
When you package the properties inside the jar file, you have to use the class loader to locate the file since it is no longer visible as a file.
If the properties file is insider the jar file at the root of the jar file then the answer given above is what you would use:
Properties p = new Properties();
InputStream is = MyClass.class.getResourceAsStream("/config.properities");
if( is != null )
{
p.load(is);
}
that should return an InputStream that you can pass to the Properities class to load. If that call returns a NULL then you need to see where the property file is relative to the root of the jar file.