Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File path after deployment

 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bean(model) in my struts application uses the following statements

...
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document domDoc = docBuilder.parse("Records.xml");
...


and further returns the values in XML file.

THis executes fine as a standalone java application.
After deploying my app in Tomcat while debugging the program stops at
'Document domDoc = docBuilder.parse("Records.xml");'

I have placed Records.xml in the classes folder under WEB-INF.

Any suggestions how I should specify tomcat specific path??

Thanks,
Gaurav.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are undoubtedly other classes upon with this class is dependent. You need to find out what the dependencies are and either include the class files themselves in WEB-INF/classes or the jar files in WEB-INF/lib. In order to find out the dependencies, I'd start by looking at what is in the classpath of your stand-alone application.
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Thanks for the reply.
Actually i have just 3 classes.
1. LoginAction.class
2. LoginForm.class
3. LoginBean.class
and on xml file -- records.xml

Login Bean reads the "records.xml" file, checks node values and returns result to the LoginForm.

I have all these placed in WEB-INF/classes.

Still do not get it right...

Gaurav

 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi all,
The solution to this is,
Place the file in classes under webapps (this is what my requirement was)
and then use the command

InputStream in = myLALoginBean.class.getResourceAsStream("/Records.xml");
---- followed by

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document domDoc = docBuilder.parse(in);

Thanks,
Gaurav Pawar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic