If you have put your XSD in package com.package with name schemFile.xsd and assume that java runtime would identify this , then I do not think this would work.Runtime would look for classes in this way not for other resources.
You might try putting the XSD file in the root of the jar and changing the file as below.
[ August 13, 2007: Message edited by: Rahul Bhattacharjee ]
Hi Eddie, I am not sure what exact error you are getting. if you are getting acess denied then you need to give permission of read to the jar file. If possible can you post your error , that will help me more
Thank for comments. Original details were a bit sketchy so for that I apologies. My original code didn't work as I could find xsd file.
I tried a few approaches so let me try yo explain
EFFORT 1 I moved it up to root of jar file and used following code:
So basically using class loader to get access to resource, creating URI and passing URI to new file. I work fine in my IDE when I am developing (gsk2c.xsd is local file) but when I test shipped jar, I get following error. Exception : com.gsk.gskgaa.exceptions.GSKGAAException: java.lang.IllegalArgument Exception: URI is not hierarchical
From some research I gather this is widely reported. And of course there is problem because I am using new File(uri), but when deployed my uri NOT a file.... it is embedded in jar file...
Now I as use CLassLoader.getResourceAsINputStream, this give me accurate handle to xsd...... however when setting attribute, I require either a file or file location (as far as I know...), I tried reading actually xsd contents and passin it to setAttribte but I got error again there.... cannot read xsd file etc
EFFORT2 I hoped to explicity read file using about approach, so i took file out of jar & added to classpath, however clasloader still looking for file in jar.... I get following NPE as classloader trying to read file from URL jar:file:/C:/NewAdapter/lib/gskgaa3.012Beta.jar!/gsk2c.xsd
FINALLY EFFORT3 I have an external properties file. I am left with specifying explicitly where file is & using the file location when setting attribute. This is very crude but all I'm left with....
So to sumarise..... I can create an inputstream from file in jar..... but I don't where to go then..... as far as I know I need either a File object or a file location....
The men of Ireland were hurling when the gods of Greece were young
Ok I have a URI from which I can create a URL......
However when I use:
I get URI is not hierarchical at this line. However when I use
I get my old favourite..... schema_reference.4: Failed to read schema document 'jar:file:\C:\Projects\GSK\GSKGAAAdapter\lib\gsk2c.jar!\gsk2c.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.