• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Cant read XML file

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a XML file which i put in the WEB-INF/CLASSES folder , but when i run my code that tries to read this xml file , Here is the snippet of the code.
************************************************
Document doc = XMLUtil.getDocument(new InputSource((new Object()).getClass().getResourceAsStream("/" + "Trial.xml")));
*************************************************
, it always looks for the file in my c:\program files\apache group\Tomcat 4.1 directory.....ultimately i will be running all code on UNIX and i wont have access to directories outside my web-app , so how do i solve this issue ?? Please help
 
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.getResource() searches for resources in the classpath. It uses the the classloader using which ur class was loaded to do this. So if ur resource is reachable by the classloader meaning if it is in the classpath, then there should be no problem. How do you know that it is searching for the resource in the tomcat folder??
Regards
 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and more way to read resources would be to use ServletContext.getResourceAsStream(path). This will search in your web context directory.
regards.
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i know its searching there ??
because it says...cant find
c:\Program files\Apache Group\Tomcat 4.1\Delegator.xml
and i am not reading through a servlet , a Utility class is reading it
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i meant
c:\Program files\Apache Group\Tomcat 4.1\Trial.xml
 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Pappu Kumar:
i meant
c:\Program files\Apache Group\Tomcat 4.1\Trial.xml


from the javadocs for Class.getResourceAsStream()
Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.
So this method would return null, if the resource is not found. Thats the resaon I asked how du know that the resource is being searched in your tomcat folder. I think your utility class is misleading you with the message you are getting. Try to run the program without the utility class.
Regards.
 
I just had the craziest dream. This tiny ad was in it.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!