aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Servlet config file & J2EE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Servlet config file & J2EE" Watch "Servlet config file & J2EE" New topic
Author

Servlet config file & J2EE

William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

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?


Please ignore post, I have no idea what I am talking about.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

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

Joined: Mar 16, 2001
Posts: 984

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

Joined: Oct 01, 2001
Posts: 2771
    
  10

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet config file & J2EE
 
Similar Threads
Cannot call EJB from Servlet
import to eclipse
how to run servlets in J2EE without using war file , please help , urgent
Tomcat vs. Orion
Changing properties file inside of an ear