• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

ClassLoader.getSystemResource

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

please help me
 
Saloon Keeper
Posts: 28831
212
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 "/".
 
jandries Aldum
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Tim Holloway
Saloon Keeper
Posts: 28831
212
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic