java - How to get a File reference from within a JAR -


first of add have tried every proposed solution on issue still cant working.

so problem...

i have application parsing xml files. select xml file (source) , validate against xsd (this file inside jar cant access). running code within ide works fine:

xsd = new file(getclass().getresourceasstream("xsds/2014/schema.xsd").getfile()); system.out.println(xsd.getabsolutepath()); //returns: c:\users\xxx\desktop\documents\netbeansprojects\javaxmlvalidator\build\classes\app\xsds\2014\schema.xsd 

but when build application jar file , run cant reference file. when run application within jar this:

//returns: c:\users\xxx\desktop\documents\netbeansprojects\javaxmlvalidator\dist\file:c:\users\xxx\desktop\documents\netbeansprojects\javaxmlvalidator\dist\javaxmlvalidator.jar!\app\xsds\2014\schema.xsd   

the path looks ok (i think) cant correct reference file in code:

source schemafile = new streamsource(xsd); schema schema = null; try {     schema = factory.newschema(schemafile); } catch (saxexception ex) {     joptionpane.showmessagedialog(null, "invalid xml schema selected!!!\n exception: "+this.getstacktracestring(ex,"    "));     return; } 

i exception:

saxparseexception: schema_reference.4: failed read schema document  'c:\users\xxx\desktop\documents\netbeansprojects\javaxmlvalidator\dist\file:c:\users\xxx\desktop\documents\netbeansprojects\javaxmlvalidator\dist\javaxmlvalidator.jar!\app\xsds\2014\schema.xsd', because 1)could not find document; 2)the document not read; 3)the root element of document not <xsd:schema> ........ 

can suggest way have correct reference xsd file withing jar?

thanks lot

for example there project such structure:

testproject   xsdfolder     schema.xsd   javaclassfolder     someclass.java  public static class someclass {      public static url getlocalxsd() throws malformedurlexception {       url baseurl = someclass.class.getresource(someclass.class.getsimplename() + ".class");       return new url(baseurl, "../xsdfolder/schema.xsd");     } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -