How can I define some properties dynamically in Java. For now, I’m using a properties file, but I need to change these properties before installation, so these properties should be set in a file outside the jar (or install) file.
These properties define my IBatis connection.
Keep going with the .properties and load the file as a resource.
If it is in the classpath it would be found.
What I use, because it is much easier to me is a resource bundle instead.
edit
If the file is in your classpath you can loaded it either as a resource with:
Some.class.loadResource(...)or what I do is use a ResourceBundle which does basically the same.For instance if I have:
I can load that file if is in the class path. The property is outside, in “some/nested/dir”
If I run it without adding that directory to my classpath it wont work:
But if I add the directory to my classpath, then the file will be found easily.
In a similar fashion, you can have a .jar file, and put your .properties file wherever you want, you just have to include it in your classpath.
The equivalent using properties would be:
But for some reason I prefer the resource bundle.