Parsing .ecore files present in a jar file [message #1851694] |
Tue, 12 April 2022 10:13  |
Eclipse User |
|
|
|
Hi,
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 02:32   |
Eclipse User |
|
|
|
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/myplugin.example.org/model/ecorefile.ecore'
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'.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08161 seconds