I have a webapp and one of the libraries included uses this line to find a property file:
now the folder structure is like a normal webapp, there is a meta-inf, web-inf, res, a few jsps etc. (one of the jsps call a library's method which needs the property file.)
now the question is, where do i have to put the property file in order for the program to be able to read it? because it just returns null and then throws an exception when the url is supposed to be read (the url is null).
someone said i should put it in the web-inf/lib folder - didnt work
someone said i should put it in tomcat's lib folder - didnt work
someone said i should put it in tomcat's bin folder - didnt work
I'm a little confused here, since your original example seems to be filing a URL under the name of "System.props", instead of something more obvious like "remote.system.url".
One reason your attempts to locate stuff under "web-inf", however is that Java is case sensitive and it should be "WEB-INF".
Th recommended way to pull properties in a J2EE webapp is to put a copy of the properties file in the WEB-INF directory and typically in the WAR classpath (WEB-INF/classes).
To load these properties from a file named "system.properties" into a Java Properties object, you can then invoke getResourceAsStream("/WEB-INF/classes/system.properties"). Note that the property path MUST include the initial "/".
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jul 18, 2011
Oh yes, sorry, the names are in capitals (WEB-WINF etc).
I thought about using that method (getResourceAsStream() ), but the method that is called(getSystemResourse() ) is inside a library(jar) which is already deployed.
The original idea for the library was to be used in a stand alone application (not in a web app) and it works that way if the System.props file is just in src directory.
but when you make a web app and include the lib, it cant find the system.props file.
If there isn't a way that I can resolve this, ill just have to unpack, change and repack the lib...
I don't know if I'm understanding that correctly. It sounds like you want to retrieve a property file from inside a JAR that is inside the WAR.
If that's what you want, you have 2 options.
1. Put the jar in the WEB-INF/lib directory. Jars in this directory are included into the webapp's classpath. You could then access the properties via the classloader. Note that ALL files and (especially!) classes in the jar will then appear as part of the classpath for the webapp, so if you just wanted the data, that could be a problem.
2. Put the jar anywhere else and use the getResource() method. You would then have to use the Java utility ZIP classes to retrieve the property "file" from the ZIP (jar) resource.