2

I am trying to read a xsd file kept in a jar using java code kept inside the same jar. I am using the following code.

URL tmpurl = ClassLoader.getSystemResource("com/abc/filename.xsd");

Schema s = schemaFactory.newSchema(tmpurl);
jaxbUnMarshaller.setSchema(s);

It is working fine when I run it as a separate project but when I make a jar, tmpurl is null, hence the setSchema gives a null pointer exception.

Can you please a workaround that can make it run even inside a jar file.

AurA
  • 12,135
  • 7
  • 46
  • 63

1 Answers1

4

Hava you tried?

getClass().getClassLoader().getResource()

Also your classpath in manifest file in jar does matter.

Please, take a look at accepted answers in here:

Class.getResource and ClassLoader.getSystemResource: is there a reason to prefer one to another?

Loading files with ClassLoader

Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
  • Thanks, works perfectly, whatever you pointed out was absolutely correct and the given links were also helpful and informative. – AurA Jan 08 '13 at 06:44