• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassLoader to LOAD XML File

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic