1

I am using a third party library in my WebApp on tomcat.

The problem is that a class of that third party library requires initialization with an XML file

LibraryClass lb = new LibraryClass("file path.xml");

So where should I put files in tomcat directories in order to be able to access them from inside the webapp??

(Note that the class requires a String for the absolute path, not a FileStream for example)

Betamoo
  • 14,964
  • 25
  • 75
  • 109

3 Answers3

1

If you don't want the file to be downloadable, make it a resource by placing it somewhere in your Java source directory and let it be copied into WEB-INF/classes. Then use ServletRequest.getRealPath("/WEB-INF/classes/...") to turn the relative path into an absolute path.

user207421
  • 305,947
  • 44
  • 307
  • 483
1

You can keep them under WEB-INF/classes folder.You can see complete discussion about this here: Where to place configuration properties files in a JSP/Servlet web application?

Community
  • 1
  • 1
UVM
  • 9,776
  • 6
  • 41
  • 66
0

Like the other answers, I agree that the best place for these files is inside your war bundle. Unlike the other answers, I would not recommend putting the file in WEB-INF/classes as that directory is for class files, not XML files.

If path.xml is located in the war's root, then you can get access to it with something like this:

String servletDirectoryPath = this.getServletConfig().getServletContext().getRealPath("");
String xmlConfigurationFileName = "path.xml";
File xmlConfigurationFile = new File(servletDirectoryPath, xmlConfigurationFileName);
initializeThirdPartyLibrary(xmlConfigurationFile);
Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
  • It is for classes *and resources.* Putting it in the root as you suggest means it can be downloaded directly, which is not desirable. – user207421 Jun 06 '12 at 05:37