Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Parsing .ecore files present in a jar file(I have a jar file which contains a .ecore file. I would want to parse this file.)
Parsing .ecore files present in a jar file [message #1851694] Tue, 12 April 2022 14:13 Go to next message
Chaitali Agarwal is currently offline Chaitali AgarwalFriend
Messages: 3
Registered: February 2022
Junior Member

Let's say I have a jar called A.jar. This jar contains a .ecore file at location model/ecorefile.ecore

I have another program in which i want to parse this ecore file.

I have come across this code,

ResourceSet resourceSet = new ResourceSetImpl();

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl());

URI myEcoreURI = URI.createFileURI(ecoreFilePath);
Resource myEcoreResource = resourceSet.getResource(myEcoreURI, true);
Iterator<EObject> i = myEcoreResource.getAllContents();

This works fine if the ecoreFilePath is of a non-jar location(physical location of the file).

I'd like to know how can one parse this ecore file within the jar.

More precisely, what should be the value of ecoreFilePath for a file present inside of a jar.

Any help will be highly appreciated.
Re: Parsing .ecore files present in a jar file [message #1851706 is a reply to message #1851694] Wed, 13 April 2022 06:32 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 259
Registered: April 2012
Senior Member
Hi, your question should have been, which URI do I need to load the model.

When the model is in a file, you can use the 'file:/<path>' URI, created with URI.createFileURI, e.g., 'file:/path/to/folder/model/ecorefile.ecore'.

In an Eclipse context models can be loaded from projects in the workspace and installed plugins, with 'platform:/resource/<project>/<path>' and 'platform:/plugin/<plugin>/<path/' uris, e.g. 'platform:/plugin/'

When you want to directly load the model from a jar, the 'archive:file:/<location-of-plugin-jar>!/<path>' or 'jar:file:/<location-of-plugin-jar>!/<path>' can be used, e.g. 'jar:file:/path/to/myjar.jar!/model/ecorefile.ecore'.
Re: Parsing .ecore files present in a jar file [message #1851709 is a reply to message #1851706] Wed, 13 April 2022 07:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32835
Registered: July 2009
Senior Member
Yes, the question is kind of context dependent. If you're running stand-alone then the jar:file URI approach is needed. If you're running in an Eclipse application you can use a simpler approach but even here there are variations to consider. A platform:/plugin URI will load the resource from a plugin installed in the running IDE itself. More often what one wants are the development time versions of the models. The EcoreEditor, for example, does this:
  public static ResourceSet createResourceSet()
    ResourceSet result = new ResourceSetImpl();
    return result;    
This ensures that you can use platform:/resource URIs even for Ecore models that are in the target platform. I.e., this maps the physical locations of the jars or folders in the target platform to platform resource URIs that make it appear is if you've imported those into the workspace as projects.

Ed Merks
Professional Support:
Re: Parsing .ecore files present in a jar file [message #1855371 is a reply to message #1851709] Tue, 11 October 2022 01:28 Go to previous message
Frank Conover is currently offline Frank ConoverFriend
Messages: 18
Registered: October 2022
Junior Member
Are you running standalone? How did you load the sysml resources.
I've seen several threads on the issue without a working solution.
I can load the profiles but when I try to apply a stereotype I get stereotype "SysML::Block" has no Ecore definition
Previous Topic:Feature License in HTML
Next Topic:Eclipse Project Plan 4.26
Goto Forum:

Current Time: Wed Jun 07 18:11:49 GMT 2023

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

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

Back to the top