Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using schema files in a jar

 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • 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?
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic