aspose file tools*
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 Spring in Action this week in the Spring 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 !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to reference resources within EAR ?