Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Loading Schema from JAR
Loading Schema from JAR [message #24240] Thu, 03 July 2003 15:57 Go to next message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

Hey,
I would like to load my schema files from a jar file (which holds the
entire app). How do I go about doing this?
I've tried passing the URL of the resource (works when not in jar file).
Thanks,
Tim
Re: Loading Schema from JAR [message #24282 is a reply to message #24240] Thu, 03 July 2003 16:59 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

--------------19457ED2DCF6C667FF7AA8C2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tim,

When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
schema for schema is loaded using a URL that looks like this for me:

jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd

Have you tried something like this?


Tim Harris wrote:

> Hey,
> I would like to load my schema files from a jar file (which holds the
> entire app). How do I go about doing this?
> I've tried passing the URL of the resource (works when not in jar file).
> Thanks,
> Tim

--------------19457ED2DCF6C667FF7AA8C2
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Tim,
<p>When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
schema for schema is loaded using a URL that looks like this for me:
<blockquote>jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd </A></blockquote>
Have you tried something like this?
<br>&nbsp;
<p>Tim Harris wrote:
<blockquote TYPE=CITE>Hey,
<br>I would like to load my schema files from a jar file (which holds the
<br>entire app). How do I go about doing this?
<br>I've tried passing the URL of the resource (works when not in jar file).
<br>Thanks,
<br>Tim</blockquote>
</html>

--------------19457ED2DCF6C667FF7AA8C2--
Re: Loading Schema from JAR [message #24368 is a reply to message #24282] Fri, 04 July 2003 10:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

Ed,
Yes I have (i'm running on unix so the path doesn't have the d:/ but other
than that it looks identical). How is the URL loaded?
I do this:

XSDResourceImpl xsdSchemaResource =
(XSDResourceImpl)resourceSet.getResource(
org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
true);

Where schemaFile is a Java URL object generated by:

URL schemaFile = this.getClass().getResource("filename.xsd");

Thanks,
Tim

Ed Merks wrote:


> --------------19457ED2DCF6C667FF7AA8C2
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit

> Tim,

> When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
> schema for schema is loaded using a URL that looks like this for me:

>
jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd

> Have you tried something like this?
Re: Loading Schema from JAR [message #24464 is a reply to message #24368] Fri, 04 July 2003 11:56 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

--------------F9F59164A7034BE38FBF769A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tim,

I'm not sure what to suggest without more details of what you have tried and how exactly it is failing. I tried adding an Example1.xsd to the
xsd.test.jar and running

xsd-test -validate
jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd.test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example 1.xsd

That works fine. If I change URI to a .xsd file that doesn't exist, I get this stack trace:

<!-- << jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd.test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example 1x.xsd >>
-->
java.io.FileNotFoundException: JAR entry org/eclipse/xsd/test/Example1x.xsd not found in
D:\sandbox\unpackage13\eclipse\plugins\org.eclipse.xsd.test\ runtime\xsd.test.jar
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConn ection.java:109)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Jar URLConnection.java:119)
at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:466)
at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:404)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:752)
at org.eclipse.xsd.test.XSDMainTest.loadAndPrint(XSDMainTest.ja va:354)
at org.eclipse.xsd.test.XSDMainTest.run(XSDMainTest.java:233)
at org.eclipse.core.internal.boot.InternalBootLoader.run(Intern alBootLoader.java:845)
at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
at java.lang.reflect.Method.invoke(Native Method)
at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
at org.eclipse.core.launcher.Main.run(Main.java:747)
at org.eclipse.core.launcher.Main.main(Main.java:583)

You can see from this stack trace that the URIConverterImpl is called to create the input stream from the URI. In this case, it's handled as a
normal URL:

protected InputStream createURLInputStream(URI uri) throws IOException
{
URL url = new URL(uri.toString());
URLConnection urlConnection = url.openConnection();
return urlConnection.getInputStream();
}

Can you provide more details of what you've tried and how it's failing?


Tim Harris wrote:

> Ed,
> Yes I have (i'm running on unix so the path doesn't have the d:/ but other
> than that it looks identical). How is the URL loaded?
> I do this:
>
> XSDResourceImpl xsdSchemaResource =
> (XSDResourceImpl)resourceSet.getResource(
> org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
> true);
>
> Where schemaFile is a Java URL object generated by:
>
> URL schemaFile = this.getClass().getResource("filename.xsd");
>
> Thanks,
> Tim
>
> Ed Merks wrote:
>
> > --------------19457ED2DCF6C667FF7AA8C2
> > Content-Type: text/plain; charset=us-ascii
> > Content-Transfer-Encoding: 7bit
>
> > Tim,
>
> > When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
> > schema for schema is loaded using a URL that looks like this for me:
>
> >
> jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd
>
> > Have you tried something like this?

--------------F9F59164A7034BE38FBF769A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Tim,
<p>I'm not sure what to suggest without more details of what you have tried
and how exactly it is failing.&nbsp; I tried adding an Example1.xsd to
the xsd.test.jar and running
<blockquote>xsd-test -validate jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1.xs d "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1.xs d </A></blockquote>
That works fine.&nbsp; If I change URI to a .xsd file that doesn't exist,
I get this stack trace:
<blockquote>&lt;!-- &lt;&lt; jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1 "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1 </A><font color="#FF0000">x</font>.xsd
>> -->
<br>java.io.FileNotFoundException: JAR entry org/eclipse/xsd/test/Example1<font color="#FF0000">x</font>.xsd
not found in D:\sandbox\unpackage13\eclipse\plugins\org.eclipse.xsd.test\ runtime\xsd.test.jar
<br>&nbsp;at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConn ection.java:109)
<br>&nbsp;at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Jar URLConnection.java:119)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:466)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:404)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:752)
<br>&nbsp;at org.eclipse.xsd.test.XSDMainTest.loadAndPrint(XSDMainTest.ja va:354)
<br>&nbsp;at org.eclipse.xsd.test.XSDMainTest.run(XSDMainTest.java:233)
<br>&nbsp;at org.eclipse.core.internal.boot.InternalBootLoader.run(Intern alBootLoader.java:845)
<br>&nbsp;at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
<br>&nbsp;at java.lang.reflect.Method.invoke(Native Method)
<br>&nbsp;at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
<br>&nbsp;at org.eclipse.core.launcher.Main.run(Main.java:747)
<br>&nbsp;at org.eclipse.core.launcher.Main.main(Main.java:583)</blockquote >
You can see from this stack trace that the URIConverterImpl is called to
create the input stream from the URI.&nbsp; In this case, it's handled
as a normal URL:
<blockquote>&nbsp; protected InputStream createURLInputStream(URI uri)
throws IOException
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; URL url = new URL(uri.toString());
<br>&nbsp;&nbsp;&nbsp; URLConnection urlConnection = url.openConnection();
<br>&nbsp;&nbsp;&nbsp; return urlConnection.getInputStream();
<br>&nbsp; }</blockquote>
Can you provide more details of what you've tried and how it's failing?
<br>&nbsp;
<p>Tim Harris wrote:
<blockquote TYPE=CITE>Ed,
<br>Yes I have (i'm running on unix so the path doesn't have the d:/ but
other
<br>than that it looks identical). How is the URL loaded?
<br>I do this:
<p>XSDResourceImpl xsdSchemaResource =
<br>&nbsp;&nbsp;&nbsp; (XSDResourceImpl)resourceSet.getResource(
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; true);
<p>Where schemaFile is a Java URL object generated by:
<p>URL schemaFile = this.getClass().getResource("filename.xsd");
<p>Thanks,
<br>Tim
<p>Ed Merks wrote:
<p>> --------------19457ED2DCF6C667FF7AA8C2
<br>> Content-Type: text/plain; charset=us-ascii
<br>> Content-Transfer-Encoding: 7bit
<p>> Tim,
<p>> When I run XSD standalone with xsd.resources.jar on the CLASSPATH,
the
<br>> schema for schema is loaded using a URL that looks like this for
me:
<p>>
<br>jar:<a href=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd </a>
<p>> Have you tried something like this?</blockquote>
</html>

--------------F9F59164A7034BE38FBF769A--
Re: Loading Schema from JAR [message #24506 is a reply to message #24464] Fri, 04 July 2003 14:19 Go to previous messageGo to next message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

Ed,
Me == Muppet!
In the class path I mistyped xsd.resources.jar as xsdresources.jar!
It now loads the main Schema file out of a jar(yay!). Unfortunately none
of the files that are included in the schema file are being loaded. I get
the following error:

java.lang.IllegalArgumentException: merge against relative path
at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
at
org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
at
org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
at
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
at
org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
at
org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
at
org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
<stack to call getResource(schema file URI)>
Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
Column 2
XSD: The location '<includedfile>.xsd' has not been resolved
<lots of XSD errors about unresolved element references>


Thanks,
Tim

Ed Merks wrote:


> Can you provide more details of what you've tried and how it's failing?
Re: Loading Schema from JAR [message #24547 is a reply to message #24464] Fri, 04 July 2003 14:21 Go to previous messageGo to next message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

FYI the error I was getting before I corrected the classpath typo was a
null return from EMFPlugin.INSTANCE.getBaseURL().
Thanks,
Tim
Re: Loading Schema from JAR [message #24588 is a reply to message #24506] Fri, 04 July 2003 16:12 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Tim,

Yes, I can reproduce this too when the schema contains relative schema locations. I need to talk to
the URI guy on Monday...

In the meantime, your best bet it to avoid zipping them into a jar. :-(


Tim Harris wrote:

> Ed,
> Me == Muppet!
> In the class path I mistyped xsd.resources.jar as xsdresources.jar!
> It now loads the main Schema file out of a jar(yay!). Unfortunately none
> of the files that are included in the schema file are being loaded. I get
> the following error:
>
> java.lang.IllegalArgumentException: merge against relative path
> at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
> at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
> at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
> at
> org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
> at
> org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
> at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
> at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
> at
> org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
> at
> org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
> <stack to call getResource(schema file URI)>
> Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
> Column 2
> XSD: The location '<includedfile>.xsd' has not been resolved
> <lots of XSD errors about unresolved element references>
>
> Thanks,
> Tim
>
> Ed Merks wrote:
>
> > Can you provide more details of what you've tried and how it's failing?
Re: Loading Schema from JAR [message #24909 is a reply to message #24588] Tue, 15 July 2003 10:56 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Tim,

The next drop of EMF/XSD 1.1.1 will contain a fix to org.eclipse.emf.common.util.URI that will allow a
relative URI to be properly resolved against a jar-scheme URI.


Ed Merks wrote:

> Tim,
>
> Yes, I can reproduce this too when the schema contains relative schema locations. I need to talk to
> the URI guy on Monday...
>
> In the meantime, your best bet it to avoid zipping them into a jar. :-(
>
> Tim Harris wrote:
>
> > Ed,
> > Me == Muppet!
> > In the class path I mistyped xsd.resources.jar as xsdresources.jar!
> > It now loads the main Schema file out of a jar(yay!). Unfortunately none
> > of the files that are included in the schema file are being loaded. I get
> > the following error:
> >
> > java.lang.IllegalArgumentException: merge against relative path
> > at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
> > at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
> > at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
> > at
> > org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
> > at
> > org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
> > at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
> > at
> > org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
> > at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
> > at
> > org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
> > at
> > org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
> > at
> > org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
> > at
> > org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
> > at
> > org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
> > at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
> > at
> > org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
> > <stack to call getResource(schema file URI)>
> > Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
> > Column 2
> > XSD: The location '<includedfile>.xsd' has not been resolved
> > <lots of XSD errors about unresolved element references>
> >
> > Thanks,
> > Tim
> >
> > Ed Merks wrote:
> >
> > > Can you provide more details of what you've tried and how it's failing?
Re: Loading Schema from JAR [message #573611 is a reply to message #24240] Thu, 03 July 2003 16:59 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26068
Registered: July 2009
Senior Member
--------------19457ED2DCF6C667FF7AA8C2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tim,

When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
schema for schema is loaded using a URL that looks like this for me:

jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd

Have you tried something like this?


Tim Harris wrote:

> Hey,
> I would like to load my schema files from a jar file (which holds the
> entire app). How do I go about doing this?
> I've tried passing the URL of the resource (works when not in jar file).
> Thanks,
> Tim

--------------19457ED2DCF6C667FF7AA8C2
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Tim,
<p>When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
schema for schema is loaded using a URL that looks like this for me:
<blockquote>jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd </A></blockquote>
Have you tried something like this?
<br>&nbsp;
<p>Tim Harris wrote:
<blockquote TYPE=CITE>Hey,
<br>I would like to load my schema files from a jar file (which holds the
<br>entire app). How do I go about doing this?
<br>I've tried passing the URL of the resource (works when not in jar file).
<br>Thanks,
<br>Tim</blockquote>
</html>

--------------19457ED2DCF6C667FF7AA8C2--
Re: Loading Schema from JAR [message #573696 is a reply to message #24282] Fri, 04 July 2003 10:36 Go to previous message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

Ed,
Yes I have (i'm running on unix so the path doesn't have the d:/ but other
than that it looks identical). How is the URL loaded?
I do this:

XSDResourceImpl xsdSchemaResource =
(XSDResourceImpl)resourceSet.getResource(
org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
true);

Where schemaFile is a Java URL object generated by:

URL schemaFile = this.getClass().getResource("filename.xsd");

Thanks,
Tim

Ed Merks wrote:


> --------------19457ED2DCF6C667FF7AA8C2
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit

> Tim,

> When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
> schema for schema is loaded using a URL that looks like this for me:

>
jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd

> Have you tried something like this?
Re: Loading Schema from JAR [message #573831 is a reply to message #24368] Fri, 04 July 2003 11:56 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26068
Registered: July 2009
Senior Member
--------------F9F59164A7034BE38FBF769A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tim,

I'm not sure what to suggest without more details of what you have tried and how exactly it is failing. I tried adding an Example1.xsd to the
xsd.test.jar and running

xsd-test -validate
jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd.test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example 1.xsd

That works fine. If I change URI to a .xsd file that doesn't exist, I get this stack trace:

<!-- << jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd.test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example 1x.xsd >>
-->
java.io.FileNotFoundException: JAR entry org/eclipse/xsd/test/Example1x.xsd not found in
D:\sandbox\unpackage13\eclipse\plugins\org.eclipse.xsd.test\ runtime\xsd.test.jar
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConn ection.java:109)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Jar URLConnection.java:119)
at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:466)
at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:404)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:752)
at org.eclipse.xsd.test.XSDMainTest.loadAndPrint(XSDMainTest.ja va:354)
at org.eclipse.xsd.test.XSDMainTest.run(XSDMainTest.java:233)
at org.eclipse.core.internal.boot.InternalBootLoader.run(Intern alBootLoader.java:845)
at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
at java.lang.reflect.Method.invoke(Native Method)
at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
at org.eclipse.core.launcher.Main.run(Main.java:747)
at org.eclipse.core.launcher.Main.main(Main.java:583)

You can see from this stack trace that the URIConverterImpl is called to create the input stream from the URI. In this case, it's handled as a
normal URL:

protected InputStream createURLInputStream(URI uri) throws IOException
{
URL url = new URL(uri.toString());
URLConnection urlConnection = url.openConnection();
return urlConnection.getInputStream();
}

Can you provide more details of what you've tried and how it's failing?


Tim Harris wrote:

> Ed,
> Yes I have (i'm running on unix so the path doesn't have the d:/ but other
> than that it looks identical). How is the URL loaded?
> I do this:
>
> XSDResourceImpl xsdSchemaResource =
> (XSDResourceImpl)resourceSet.getResource(
> org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
> true);
>
> Where schemaFile is a Java URL object generated by:
>
> URL schemaFile = this.getClass().getResource("filename.xsd");
>
> Thanks,
> Tim
>
> Ed Merks wrote:
>
> > --------------19457ED2DCF6C667FF7AA8C2
> > Content-Type: text/plain; charset=us-ascii
> > Content-Transfer-Encoding: 7bit
>
> > Tim,
>
> > When I run XSD standalone with xsd.resources.jar on the CLASSPATH, the
> > schema for schema is loaded using a URL that looks like this for me:
>
> >
> jar:file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse .xsd/runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3 .org/2001/XMLSchema.xsd
>
> > Have you tried something like this?

--------------F9F59164A7034BE38FBF769A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Tim,
<p>I'm not sure what to suggest without more details of what you have tried
and how exactly it is failing.&nbsp; I tried adding an Example1.xsd to
the xsd.test.jar and running
<blockquote>xsd-test -validate jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1.xs d "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1.xs d </A></blockquote>
That works fine.&nbsp; If I change URI to a .xsd file that doesn't exist,
I get this stack trace:
<blockquote>&lt;!-- &lt;&lt; jar:<A HREF=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1 "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd .test/runtime/xsd.test.jar!/org/eclipse/xsd/test/Example1 </A><font color="#FF0000">x</font>.xsd
>> -->
<br>java.io.FileNotFoundException: JAR entry org/eclipse/xsd/test/Example1<font color="#FF0000">x</font>.xsd
not found in D:\sandbox\unpackage13\eclipse\plugins\org.eclipse.xsd.test\ runtime\xsd.test.jar
<br>&nbsp;at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConn ection.java:109)
<br>&nbsp;at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Jar URLConnection.java:119)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:466)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:404)
<br>&nbsp;at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:752)
<br>&nbsp;at org.eclipse.xsd.test.XSDMainTest.loadAndPrint(XSDMainTest.ja va:354)
<br>&nbsp;at org.eclipse.xsd.test.XSDMainTest.run(XSDMainTest.java:233)
<br>&nbsp;at org.eclipse.core.internal.boot.InternalBootLoader.run(Intern alBootLoader.java:845)
<br>&nbsp;at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
<br>&nbsp;at java.lang.reflect.Method.invoke(Native Method)
<br>&nbsp;at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
<br>&nbsp;at org.eclipse.core.launcher.Main.run(Main.java:747)
<br>&nbsp;at org.eclipse.core.launcher.Main.main(Main.java:583)</blockquote >
You can see from this stack trace that the URIConverterImpl is called to
create the input stream from the URI.&nbsp; In this case, it's handled
as a normal URL:
<blockquote>&nbsp; protected InputStream createURLInputStream(URI uri)
throws IOException
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; URL url = new URL(uri.toString());
<br>&nbsp;&nbsp;&nbsp; URLConnection urlConnection = url.openConnection();
<br>&nbsp;&nbsp;&nbsp; return urlConnection.getInputStream();
<br>&nbsp; }</blockquote>
Can you provide more details of what you've tried and how it's failing?
<br>&nbsp;
<p>Tim Harris wrote:
<blockquote TYPE=CITE>Ed,
<br>Yes I have (i'm running on unix so the path doesn't have the d:/ but
other
<br>than that it looks identical). How is the URL loaded?
<br>I do this:
<p>XSDResourceImpl xsdSchemaResource =
<br>&nbsp;&nbsp;&nbsp; (XSDResourceImpl)resourceSet.getResource(
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; org.eclipse.emf.common.util.URI.createURI(schemaFile.toStrin g()),
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; true);
<p>Where schemaFile is a Java URL object generated by:
<p>URL schemaFile = this.getClass().getResource("filename.xsd");
<p>Thanks,
<br>Tim
<p>Ed Merks wrote:
<p>> --------------19457ED2DCF6C667FF7AA8C2
<br>> Content-Type: text/plain; charset=us-ascii
<br>> Content-Transfer-Encoding: 7bit
<p>> Tim,
<p>> When I run XSD standalone with xsd.resources.jar on the CLASSPATH,
the
<br>> schema for schema is loaded using a URL that looks like this for
me:
<p>>
<br>jar:<a href=" file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd "> file:/D:/sandbox/unpackage13/eclipse/plugins/org.eclipse.xsd /runtime/xsd.resources.jar!/org/eclipse/xsd/cache/www.w3.org /2001/XMLSchema.xsd </a>
<p>> Have you tried something like this?</blockquote>
</html>

--------------F9F59164A7034BE38FBF769A--
Re: Loading Schema from JAR [message #573868 is a reply to message #24464] Fri, 04 July 2003 14:19 Go to previous message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

Ed,
Me == Muppet!
In the class path I mistyped xsd.resources.jar as xsdresources.jar!
It now loads the main Schema file out of a jar(yay!). Unfortunately none
of the files that are included in the schema file are being loaded. I get
the following error:

java.lang.IllegalArgumentException: merge against relative path
at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
at
org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
at
org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
at
org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
at
org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
at
org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
at
org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
<stack to call getResource(schema file URI)>
Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
Column 2
XSD: The location '<includedfile>.xsd' has not been resolved
<lots of XSD errors about unresolved element references>


Thanks,
Tim

Ed Merks wrote:


> Can you provide more details of what you've tried and how it's failing?
Re: Loading Schema from JAR [message #573898 is a reply to message #24464] Fri, 04 July 2003 14:21 Go to previous message
Eclipse User
Originally posted by: tim.harris.snellwilcox.com

FYI the error I was getting before I corrected the classpath typo was a
null return from EMFPlugin.INSTANCE.getBaseURL().
Thanks,
Tim
Re: Loading Schema from JAR [message #573926 is a reply to message #24506] Fri, 04 July 2003 16:12 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26068
Registered: July 2009
Senior Member
Tim,

Yes, I can reproduce this too when the schema contains relative schema locations. I need to talk to
the URI guy on Monday...

In the meantime, your best bet it to avoid zipping them into a jar. :-(


Tim Harris wrote:

> Ed,
> Me == Muppet!
> In the class path I mistyped xsd.resources.jar as xsdresources.jar!
> It now loads the main Schema file out of a jar(yay!). Unfortunately none
> of the files that are included in the schema file are being loaded. I get
> the following error:
>
> java.lang.IllegalArgumentException: merge against relative path
> at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
> at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
> at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
> at
> org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
> at
> org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
> at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
> at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
> at
> org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
> at
> org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
> at
> org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
> <stack to call getResource(schema file URI)>
> Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
> Column 2
> XSD: The location '<includedfile>.xsd' has not been resolved
> <lots of XSD errors about unresolved element references>
>
> Thanks,
> Tim
>
> Ed Merks wrote:
>
> > Can you provide more details of what you've tried and how it's failing?
Re: Loading Schema from JAR [message #574285 is a reply to message #24588] Tue, 15 July 2003 10:56 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26068
Registered: July 2009
Senior Member
Tim,

The next drop of EMF/XSD 1.1.1 will contain a fix to org.eclipse.emf.common.util.URI that will allow a
relative URI to be properly resolved against a jar-scheme URI.


Ed Merks wrote:

> Tim,
>
> Yes, I can reproduce this too when the schema contains relative schema locations. I need to talk to
> the URI guy on Monday...
>
> In the meantime, your best bet it to avoid zipping them into a jar. :-(
>
> Tim Harris wrote:
>
> > Ed,
> > Me == Muppet!
> > In the class path I mistyped xsd.resources.jar as xsdresources.jar!
> > It now loads the main Schema file out of a jar(yay!). Unfortunately none
> > of the files that are included in the schema file are being loaded. I get
> > the following error:
> >
> > java.lang.IllegalArgumentException: merge against relative path
> > at org.eclipse.emf.common.util.URI.mergePath(URI.java:1260)
> > at org.eclipse.emf.common.util.URI.resolve(URI.java:1239)
> > at org.eclipse.emf.common.util.URI.resolve(URI.java:1172)
> > at
> > org.eclipse.xsd.util.XSDConstants.resolveSchemaLocation(XSDC onstants.java:1493)
> > at
> > org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchem aDirectiveImpl.java:368)
> > at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.jav a:324)
> > at
> > org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcr eteComponentImpl.java:513)
> > at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java: 1494)
> > at
> > org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchema Impl.java:2240)
> > at
> > org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDCon creteComponentImpl.java:1205)
> > at
> > org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSche maImpl.java:842)
> > at
> > org.eclipse.xsd.util.XSDResourceImpl.attached(XSDResourceImp l.java:352)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:326)
> > at
> > org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:238)
> > at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:5 58)
> > at
> > org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl. java:316)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:881)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:755)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:220)
> > at
> > org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:286)
> > <stack to call getResource(schema file URI)>
> > Warning: URI jar:file:<path_to_jar>.jar!<path_to_schema>.xsd Line 17
> > Column 2
> > XSD: The location '<includedfile>.xsd' has not been resolved
> > <lots of XSD errors about unresolved element references>
> >
> > Thanks,
> > Tim
> >
> > Ed Merks wrote:
> >
> > > Can you provide more details of what you've tried and how it's failing?
Previous Topic:ResourceSetImpl.getResource exception
Next Topic:Analysing Schemas
Goto Forum:
  


Current Time: Wed Sep 24 00:31:20 GMT 2014

Powered by FUDForum. Page generated in 0.02350 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software