• 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

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
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic