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.

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

Sun Certified Enterprise Architect<br />Saurabh

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308

posted Aug 14, 2007 00:07:00

0

If you are not running the program with security manager enabled , then no problem.You will not get access controller exception. Have you tried the solution that I suggested you in my previous post?

Eddie Howard
Greenhorn

Joined: Jul 27, 2006
Posts: 14

posted Aug 14, 2007 07:32:00

0

Hi Guys

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 fromURL 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....

you are able to pass a URI when it is on the local file system, but you missed the fact that gskgaa3.012Beta.jar!/gsk2c.xsd represents the URL for the file within the JAR.

Eddie Howard
Greenhorn

Joined: Jul 27, 2006
Posts: 14

posted Aug 14, 2007 09:01:00

1

Ok..... I will try that..... Thanks!!

Eddie Howard
Greenhorn

Joined: Jul 27, 2006
Posts: 14

posted Aug 14, 2007 09:47:00

0

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>.