Today in my project I had a requirement to fetch the properties file from out side of my JAR file. Its easy to pick it from the CLASSPATH of that JAR file but not that much easy to pick from a "Special location" like TOMCAT home, outside the JAR file. At first I tried to read it as a ResourceBundle. But with our so much difference I done it as follows...
String path = System.getProperty("catalina.base")
+ System.getProperty("file.seperator")
+ "YOUR_FILE.properties";
FileInputStream fis = new FileInputStream(path); Properties props = new Properties(); props.load(fis); fis.close();
I am putting some more code examples here which I came across my search. Hope this helps anyone.
1. If the resource file is located in your CLASSPATH, then
objRes = ResourceBundle.getBundle("/ResFile.Application");
These two are also helpful
2. Reading from another JAR (Source : here)
If your program is in an executable jar file then add the following in the manifest file inside your JAR
class-path: jarname.jar
jarname.jar has "some/path/myconfig.properties" file
To access the properties in junk from your executable jar file in your class, do the following
Locale eng = Locale.ENGLISH; String myvalue = java.util.ResourceBundle
.getBundle("some/path/myconfig",eng).getString("greeting");
3. Verifying the Location (Source: here ) In your code, make sure that you are correctly requesting the resource. If you are requesting a resource from the directory where you are running your jar file from (i.e. the working directory), simply use ResourceBundle.getBundle("Resource"); or equivalent method.
If you bundle is within a directory, you must specify the directory when getting the Bundle as a dot separated string, i.e.
ResourceBundle.getBundle("etc.i18n.Resource"); would look for the file <working-directory)/etc/i18n/Resource.properties.