Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Use .jar as Xtext resource
Use .jar as Xtext resource [message #1838777] Thu, 04 March 2021 20:44 Go to next message
Jeremy Davies is currently offline Jeremy DaviesFriend
Messages: 4
Registered: March 2021
Junior Member
Hi all,

Previously I was adding to a resource set (running as standalone) using:

String file = "file:///c:/foo.dp";
(LazyLinkingResource) resourceSet.getResource(URI.createURI(file),true); 


Now, imagine that same foo.dp model is contained in a .jar file named foo.jar. Am I able to use this as a resource in a similar fashion as I don't really want to unpack the archive locally and then use a file URI .

String file = "file:///c:/foo.jar";
(LazyLinkingResource) resourceSet.getResource(URI.createURI(file),true); 


When I try this I get the following

Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'file:///c:/foo.jar'; a registered resource factory is needed
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:262)
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:25)



Thanks in advance,

Jez

Re: Use .jar as Xtext resource [message #1838791 is a reply to message #1838777] Fri, 05 March 2021 06:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Use a scheme like archive, zip, or jar to access it. That works with any underlying URI scheme, not just file:, i.e., archive:<URI-of-jar/zip>!/<path-in-jar-zip-to-file-resource>, e.g., like this:

archive:http://www.eclipse.org/setups/setups.zip!/http/git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/org.eclipse.setup


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Use .jar as Xtext resource [message #1838819 is a reply to message #1838791] Fri, 05 March 2021 16:52 Go to previous messageGo to next message
Jeremy Davies is currently offline Jeremy DaviesFriend
Messages: 4
Registered: March 2021
Junior Member
Hi - I can't open the link
Re: Use .jar as Xtext resource [message #1838828 is a reply to message #1838819] Fri, 05 March 2021 20:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
It's an example. A browser can't open such a link. A browser can't even open a link that uses jar: scheme, but a Java application can do that.; that's how Java works with jars on a classpath....

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Use .jar as Xtext resource [message #1839034 is a reply to message #1838828] Thu, 11 March 2021 15:55 Go to previous messageGo to next message
Jeremy Davies is currently offline Jeremy DaviesFriend
Messages: 4
Registered: March 2021
Junior Member
Got it.

Ok that works and I can load each resource into the resourceSet.

Now when I call the EcoreUtil.resolveAll() method I am still left with eProxyURL refs instead of concrete classes, not all the time, but sometimes.

I read on another forum post that I had to use platform:/resource or similar but I don't know how to do that.

Let's imagine my model is this:

- root/A.gen
- root/component/B.gen

And A has an array of class Bs
A.component = [B1, B2, B3]

resourceSet.getResource(URI.createURI("archive:file:///c:/mydir/myjar.jar!/root/A.gen"), true);
resourceSet.getResource(URI.createURI("archive:file:///c:/mydir/myjar.jar!/root/components/B1.gen"), true);
resourceSet.getResource(URI.createURI("archive:file:///c:/mydir/myjar.jar!/root/components/B2.gen"), true);
resourceSet.getResource(URI.createURI("archive:file:///c:/mydir/myjar.jar!/root/components/B3.gen"), true);


I then call:
EcoreUtil.resolveAll(resourceSet);


The resources are LazyLinkedResources - when I inspect the model and look at the proxyInformation variable I see an array of triples, the first of which points at a reference, as shown below:

If I'm looking at the in-memory model for A.gen I then see something similar to:

com.blah.A@250268ef (eProxyURI: archive:file:///c:/mydir/myjar.jar!/root/components/B1.gen#|1)


I just want to be able to resolve that reference and bring the contents of B into that location.

[Updated on: Thu, 11 March 2021 15:59]

Report message to a moderator

Re: Use .jar as Xtext resource [message #1839035 is a reply to message #1839034] Thu, 11 March 2021 16:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
I don't know if anything special about Xtext is involved when resolving the fragment '#|1' . I can't comment on that in general. But if the resource itself loads with URI 'archive:file:///c:/mydir/myjar.jar!/root/components/B1.gen' then the problem has to be resolving the fragment within that resource which is specialized by the LazyLinkedResource implementation.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Use .jar as Xtext resource [message #1839039 is a reply to message #1839035] Thu, 11 March 2021 16:25 Go to previous messageGo to next message
Jeremy Davies is currently offline Jeremy DaviesFriend
Messages: 4
Registered: March 2021
Junior Member
Do you know how I can get get the .jar file described above to be made available via:

"platform:/resource/blah/A.get"

[Updated on: Thu, 11 March 2021 16:28]

Report message to a moderator

Re: Use .jar as Xtext resource [message #1839047 is a reply to message #1839039] Thu, 11 March 2021 18:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
If your files are physcally in a jar and you want to access them in that jar directly, I don't see that platform:/resource will help. This is scheme typically used to reference things in an Eclipe workspace....

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Use .jar as Xtext resource [message #1839094 is a reply to message #1839047] Sat, 13 March 2021 14:40 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Quote:
I don't know if anything special about Xtext is involved when resolving the fragment '#|1' .


~|nnn is very special in Xtext. I think nnn is the nnn'th unresolved reference in the concrete syntax text. It is passed as a triple to the LinkingService when standard EMF activities resolve the proxy.

Regards

Ed
Previous Topic:[CDO] RootResourceID is null error - Workaround
Next Topic:model.ecore is not generated in /model/impl during 'clean install' maven goal
Goto Forum:
  


Current Time: Fri Apr 26 14:38:13 GMT 2024

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

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

Back to the top