• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Servlet config file & J2EE

 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an J2EE / ant / Servlet question. And since I was only able to post it once it goes here (as the J2EE forum seems to be mostly EJB questions).
I had a Servlet which worked under WS 3.5. I changed the ant file to support creating a 'ear' file. There was a config file that the Servlet used and I wanted to include that in the 'ear' file.
The Servlet looked for config file in the directory in which is runs. And that was the problem. The Servlet was not able to find the config file until I put it here: .../app/XYZ/ Everything in the 'ear' file gets installed into .../app/XYZ/installedApps/
So I was not able to figure out how to include the config file in the 'ear' file, and have settled for installing it as a separate step, outside of the 'ear' file.
Any ideas about how I would be able to include the config file in the 'ear' file, so that the Servlet would be able to find it?
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, the ear file should only contain jars and wars. If you want a servlet to pick up a config file as a resource from its classpath, you should put it in WEB-INF/classes in the war file.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct.
I didn't explain in enough detail. My build.xml makes a 'war' and an 'ear'. So the servlet config file is included in the 'war' file, which is than placed into an 'ear' file.
But I still have the same problem. I don't have any problems getting the servlet config file into the 'war' file. The problem is that when the servlet runs it is looking for the config file outside of the directory structure in which the 'war' files are placed.
 
Greg Charles
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait, are you trying to load the config file from the file system using a FileStream or FileReader? If so, then reading the file from inside a war inside an ear is going to be tough. I would use Class.getResourceAsStream(). I think the servlet should be able to find the file then. Another option is to put the config file into a well known directory on the file system and not into the ear at all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic