• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Help please: access .xsd inside a jar

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, all,
I use the following code to access my schema
URL schemaURL = getClass().getClassLoader().getResource(schemaString);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaURL.getFile());

This code works fine in my IDE. But when i deploy the project and jar up the xsd file, this code returns null exception.

When I print out the schemaString, it looks like:
mmsoffline.jar!/NdpStatusUpdate.xsd

Any ideas how to resolve this problem?
thanks a lot!
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Denis,

Try some thing like this :

public void readFile() throws Exception
{
ClassLoader loader = ClassLoader.getSystemClassLoader ();
InputStream is = loader.getResourceAsStream ("myxml.xml");
URL schemaURL = loader.getResource("myxml.xml");
}
Then wrap the above into something that suits your requirement , it might be one from the list below.

Possible values for schema source property :

*A string that points to the URI of the schema
*An InputStream with the contents of the schema
*A SAX InputSource
*A File
*An array of Objects, each of which is one of the types defined here

Hope this helps.

Regards
Bajji Pat
 
Denis Wang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your kindly reply. However, i missed one point in my previous message. (Otherwise your code will definitely work.)

My schema includes another common schema, which is also located in the jar file:
<xs:include schemaLocation="FQ-Common.xsd" />

How to handle this situation.

Best,
Denis
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic