• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Using schema files in a jar

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to be able to package my app in a jar file including all schema (xsd) files.

I am using JDOM w/xerces as its parser. I know how to configure the parser through JDOM to use schema validation and to specify an external schema file residing on the file system.

But, I am unsure of how to instruct the parser to validate using the jarred schema files? i.e. How can the parser read from the jar?

I read on some post about creating a custom EntityResolver that uses the classpath to locate the schema file but I'm just wondering if there is a better solution?
 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YourClass.getClass().getResourceAsStream( .. ) will load it from the classpath
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pho Tek:
YourClass.getClass().getResourceAsStream( .. ) will load it from the classpath

That would work if I could simply pass the InputStream to the parser, but I'm not aware of any way to do that.

For example, according to the JDOM docs, to tell the parser where the schema file is:Where weblog.xsd is the file spec.

So, unless I'm missing something, it looks as though you have to specify the location as a file spec. But it seems like there should be a mechanism built into the parser to load it from the classpath instead.
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I believe I found the solution to my problem.
The schema location can also be a URL string so I can use ClassLoader.getResource() which returns the URL (jar:...) of the schema file. Then I can simply do this:Thanks for your help.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic