• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to reference resources within EAR ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic