• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassLoader to LOAD XML File  RSS feed

 
dileep keely
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam trying to load an xml file which is in the WEB-INF/classes/report folder of war file, but with no luck..
Note: Due to some restrictions I dont want to use ServletContext/any thing related to servlet..I want to develop only plain java related code which does loading
the ..

System.out.println("9:"+DataDiscrepancyXMLParser.class.getClassLoader().getResource("/WEB-INF/classes/lsorDataDiscrepancyReport.xml").getPath());

I deployed in jboss and I get the below system output:
C:/softwares/Middleware/user_projects/domains/lsor_domain/servers/AdminServer/tmp/_WL_user/lsorFS/ie6ar8/war/WEB-INF/lib/_wl_cls_gen.jar!/lsorDataDiscrepancyReport.xml

When I try to read it I get Filenotfundexception..
My assumpton was that I would instead get the path as "/web-inf/classes/sorDataDiscrepancyReport.xml.

Please suggest

 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use getResourceAsStream instead of getResource? getResourceAsStream gives you an InputStream (or null if not found!) that you can use instead of a FileInputStream. It's more portable because if you deploy your WAR on another container it may not get unpacked, and the resource will not be available as a file. It will still be available as a resource though.
 
dileep keely
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I soon realized after I posted and used getResourceAsStream().. Steps I followed are as below.
1.Load XML and XSD files (XMLstream,XSDStream) ->success.
2.XML validated with respect to XSD using saxparser ->success.
3.After validation is successful, I want to generate the Objects out of XML(Unmarshal). During which I got nullpoiniter exception.

I realized that as I am trying to use the same loaded XMLStream which might be closed/flush by SAX API internally during parsing.
My idea is to reload the XML again for unmarshalling. Please let me know if my understanding is right with respect to reloading the XML again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!