• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet config file & J2EE

 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • 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?
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • 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: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic