This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes How to reference resources within EAR ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to reference resources within EAR ?" Watch "How to reference resources within EAR ?" New topic
Author

How to reference resources within EAR ?

John Luckcuck
Greenhorn

Joined: Apr 18, 2002
Posts: 7
Does anybody know how to reference a directory packaged within an EAR file other than using a System property to manualy specify the absolute location of the installed EAR. In my code, I want to load a properties file in a config directory packaged within my WAR.
If I do a 'new File("config/config.props")' the code looks in the bin directory of my appserver! I cannot seem to reference file resources within my EAR.
Please Help
Cheers,
John


J2EE Web Developer
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
An option that is open to you is to load such resources with the ClassLoader, for example, using getClass().getResource("/myResources.properties"). This means that you can then simply include resources inside your JAR files.
Of course, if you are loading resources from a webapp within an EAR file, you can also use getServletContext().getResource() if your resources are underneath the WEB-INF directory of your web application.
Using a system property to directly reference the deployed location of an EAR file is not the best thing to do, simply because the app servers are free to copy and unextract the contents into a directory on deployment.
Hope that helps
Simon
John Luckcuck
Greenhorn

Joined: Apr 18, 2002
Posts: 7
Simon, your a star ! I'd tried the class.getResource("") method before but it kept giving me the runtime of the appserver, but the getServletContext().getResource() works fine. Many thanks !
 
 
subject: How to reference resources within EAR ?
 
Similar Threads
Dynamic re-loading of class files
How to have my own log4j.xml file in Jboss
Accessing resources outside of the Jar
Deploye Enterprise application in Server
How do I read a file from the META-INF directory?