Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Feature 'XMI' not found when error message when loading large ecore models
[EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1561060] Tue, 13 January 2015 00:03 Go to next message
Justin Field is currently offline Justin FieldFriend
Messages: 7
Registered: July 2014
Junior Member
Hi Everyone,

I have generated an EMF model with a variety of .ecore packages from a large XML standard. I've also generated the Java code from these models, but some of the .ecore files were so large that the "Initialize by Loading" setting is set to true.

These models are being used in a variety of maven projects that build on top of each other. The first layer holds the generated Java code from the EMF model. That project is a dependency on another that holds all of the logic that converts between my standard business objects and the EMF objects. That second project is being used as a dependency on a third(while actually multiple others) that contains the actual business logic. Currently, all of these are being ran in eclipse, but I will eventually want to be able to run them stand alone, which I see will eventually require some additional setup.

The problem I am currently trying to solve occurs when I attempt to initialize some of the larger ecore models in the business logic projects(so two layers of transitive dependencies from the original model project.) When I attempt to register my packages via a line like this:

_3Package.eINSTANCE.eClass();


I get a stack trace that looks like this(I've shortened it a bit!):
Exception in thread "main" java.lang.ExceptionInInitializerError at net.opengis.ows._1.impl._1PackageImpl.init(_1PackageImpl.java:574)

Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (file:/C:/workspaces/pathToModel.ecore, 3, 120)

Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (file:/C:/workspaces/pathToModel.ecore, 3, 120)

 org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'xmi' not found. (file:/C:/workspaces/pathToModel.ecore, 3, 120))
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeature(XMIHandler.java:145)


The parts of the model I think are relevant look something like this:

Note: I've had to mangle the URL's to get past some messages about only having links to eclipse.org.  

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="path/XMI" xmlns:xsi="path/XMLSchema-instance"
    xmlns:ecore="path/Ecore" name="_3" nsURI="path/gml/3.2" nsPrefix="_3">


This error does not occur in the lower level modules for some reason. I admittedly don't have a great understanding of EMF yet, but I've been googling a bit and can't seem to get things right.

I've tried a variety of lines that look something like this:
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());

but that hasn't seemed to help. I've also tried to place the plugin.xml and plugin.properties files from my base-level EMF project into the later projects but that didn't work either.

Any help anyone can provide is greatly appreciated. Thank you for your time!
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1562089 is a reply to message #1561060] Tue, 13 January 2015 13:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Justin,

Comments below.

On 13/01/2015 1:03 AM, Justin Field wrote:
> Hi Everyone,
>
> I have generated an EMF model with a variety of .ecore packages from a
> large XML standard. I've also generated the Java code from these
> models, but some of the .ecore files were so large that the
> "Initialize by Loading" setting is set to true.
> These models are being used in a variety of maven projects that build
> on top of each other. The first layer holds the generated Java code
> from the EMF model. That project is a dependency on another that
> holds all of the logic that converts between my standard business
> objects and the EMF objects. That second project is being used as a
> dependency on a third(while actually multiple others) that contains
> the actual business logic. Currently, all of these are being ran in
> eclipse, but I will eventually want to be able to run them stand
> alone, which I see will eventually require some additional setup.
>
> The problem I am currently trying to solve occurs when I attempt to
> initialize some of the larger ecore models in the business logic
> projects(so two layers of transitive dependencies from the original
> model project.) When I attempt to register my packages via a line like
> this:
>
> _3Package.eINSTANCE.eClass();
>
> I get a stack trace that looks like this(I've shortened it a bit!):
>
> Exception in thread "main" java.lang.ExceptionInInitializerError at
> net.opengis.ows._1.impl._1PackageImpl.init(_1PackageImpl.java:574)
>
> Caused by: org.eclipse.emf.common.util.WrappedException:
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'xmi' not found. (file:/C:/workspaces/pathToModel.ecore, 3, 120)
>
> Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException:
> Feature 'xmi' not found. (file:/C:/workspaces/pathToModel.ecore, 3, 120)
I'd expect an error like this only if an XMIResourceImpl of some sort
isn't used to parse the file, but the generated initialization code does
this:

public void loadPackage() {
if (isLoaded) return;
isLoaded = true;

URL url = getClass().getResource(packageFilename);
if (url == null) {
throw new RuntimeException("Missing serialized package: " +
packageFilename);
}
URI uri = URI.createURI(url.toString());
Resource resource = new
EcoreResourceFactoryImpl().createResource(uri);
try {
resource.load(null);
}
catch (IOException exception) {
throw new WrappedException(exception);
}
initializeFromLoadedEPackage(this,
(EPackage)resource.getContents().get(0));
createResource(eNS_URI);
}


>
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'xmi' not
> found. (file:/C:/workspaces/pathToModel.ecore, 3, 120))
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeature(XMIHandler.java:145)
>
>
> The parts of the model I think are relevant look something like this:
>
>
> Note: I've had to mangle the URL's to get past some messages about
> only having links to eclipse.org.
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0" xmlns:xmi="path/XMI"
> xmlns:xsi="path/XMLSchema-instance"
> xmlns:ecore="path/Ecore" name="_3" nsURI="path/gml/3.2" nsPrefix="_3">
>
>
> This error does not occur in the lower level modules for some reason.
> I admittedly don't have a great understanding of EMF yet, but I've
> been googling a bit and can't seem to get things right.
>
> I've tried a variety of lines that look something like this:
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
> new XMIResourceFactoryImpl());
> but that hasn't seemed to help. I've also tried to place the
> plugin.xml and plugin.properties files from my base-level EMF project
> into the later projects but that didn't work either.
> Any help anyone can provide is greatly appreciated. Thank you for
> your time!
Is this really happening from a generated package's loadPackage method?
I can't reproduce any such problem when I try to run the XyzExample.java
from a generated *.test project, so there isn't an obvious/inherent
problem I can see with stand alone loaded packaged initialization...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1562591 is a reply to message #1562089] Tue, 13 January 2015 20:06 Go to previous messageGo to next message
Justin Field is currently offline Justin FieldFriend
Messages: 7
Registered: July 2014
Junior Member
Ed, thanks for your help! That code block you mentioned before with the call to loadPackage() is where I am failing on the call to resouce.load(null). I have modified the line

URL url = getClass().getResource(packageFilename);
to be
URL url = getClass().getResource("/" + packageFilename);
so that I could place the .ecore files in the resource files as I was having problems determining where exactly to put them in the subproject without that.

For further experimentation I took a look at the _3Example.java file generated by the model code. It think the relevant parts our something like this:
        // Create a resource set to hold the resources.
        //
        ResourceSet resourceSet = new ResourceSetImpl();
        
        // Register the appropriate resource factory to handle all file extensions.
        //
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
            (Resource.Factory.Registry.DEFAULT_EXTENSION, 
             new _3ResourceFactoryImpl());

        // Register the package to ensure it is available during loading.
        //
        resourceSet.getPackageRegistry().put
            (_3Package.eNS_URI,  _3Package.eINSTANCE);
        
// Had to add this line, otherwise it said something like "version" not found.      
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());

                File file = new File(args[i]);
                URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);

                try {
                    // Demand load resource for this file.
                    //
                    Resource resource = resourceSet.getResource(uri, true);
                    System.out.println("Loaded " + uri);


This code failed in the original generated test package because it couldn't find the ecore files. That makes sense as I slightly modified the loadPackage() method and it failed with the "Missing serialized package" message. No problems here.

I copied the same class into the next project that depends directly on my generated modules. I was able to successfully load the resource without any problems.

I then copied the class into a project one level higher(where I really need it to be). This is where it seems to fail on the _3Package.eInstance call.
I attempted to add this line
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());

before the call as I believe it registers the ecore files to the XMIResourceFactoryImpl globally. It gets into loadPackage and fails while attempting to read the model.

I'm thinking maybe I'm losing some sort of configuration option somewhere as I go up the chain, but I'm not real sure what to look for.

Thanks again for your help!
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1564027 is a reply to message #1562591] Wed, 14 January 2015 15:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Justin,

Comments below.

On 13/01/2015 9:06 PM, Justin Field wrote:
> Ed, thanks for your help! That code block you mentioned before with
> the call to loadPackage() is where I am failing on the call to
> resouce.load(null). I have modified the line
> URL url = getClass().getResource(packageFilename); to be URL url =
> getClass().getResource("/" + packageFilename); so that I could place
> the .ecore files in the resource files as I was having problems
> determining where exactly to put them in the subproject without that.
It should be relative to the class; normally the builder will copy such
files to the bin folder and when you publish to a jar it should end up
in the jar in the same folder as the package class. Again, this just
works out of the box for me...
> For further experimentation I took a look at the _3Example.java file
> generated by the model code. It think the relevant parts our
> something like this:
>
> // Create a resource set to hold the resources.
> //
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register the appropriate resource factory to handle
> all file extensions.
> //
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,
> new _3ResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put
> (_3Package.eNS_URI, _3Package.eINSTANCE);
> // Had to add this line, otherwise it said something like
> "version" not found.
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new XMIResourceFactoryImpl());
But the generated code explicitly uses

Resource resource = new
EcoreResourceFactoryImpl().createResource(uri);
>
> File file = new File(args[i]);
> URI uri = file.isFile() ?
> URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
>
> try {
> // Demand load resource for this file.
> //
> Resource resource = resourceSet.getResource(uri,
> true);
> System.out.println("Loaded " + uri);
>
>
> This code failed in the original generated test package because it
> couldn't find the ecore files. That makes sense as I slightly
> modified the loadPackage() method and it failed with the "Missing
> serialized package" message. No problems here.
It's hard to comment on slight modifications... Without modification it
just works for me.
>
> I copied the same class into the next project that depends directly on
> my generated modules. I was able to successfully load the resource
> without any problems.
> I then copied the class into a project one level higher(where I really
> need it to be). This is where it seems to fail on the
> _3Package.eInstance call. I attempted to add this line
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
> new XMIResourceFactoryImpl());
Given the code explicitly uses EcoreResourceFactoryImpl it's hard to
understand why a registration is required...
>
> before the call as I believe it registers the ecore files to the
> XMIResourceFactoryImpl globally. It gets into loadPackage and fails
> while attempting to read the model.
> I'm thinking maybe I'm losing some sort of configuration option
> somewhere as I go up the chain, but I'm not real sure what to look for.
> Thanks again for your help!
I can't comment on your slight modifications without seeing them.
Without any modifications to the generated code, which exactly fails?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1564567 is a reply to message #1564027] Wed, 14 January 2015 21:46 Go to previous messageGo to next message
Justin Field is currently offline Justin FieldFriend
Messages: 7
Registered: July 2014
Junior Member
Thanks again for your responses Ed! I've commented a bit more below.

>> Ed, thanks for your help! That code block you mentioned before with
>> the call to loadPackage() is where I am failing on the call to
>> resouce.load(null). I have modified the line
>> URL url = getClass().getResource(packageFilename); to be URL url =
>> getClass().getResource("/" + packageFilename); so that I could place
>> the .ecore files in the resource files as I was having problems
>> determining where exactly to put them in the subproject without that.

> It should be relative to the class; normally the builder will copy such
> files to the bin folder and when you publish to a jar it should end up
> in the jar in the same folder as the package class. Again, this just
> works out of the box for me...
Hmm, my main EMF project is actually setup as a maven project that by a former employee, so I'm not really sure how things have potentially changed from the default. I don't have a bin directory so that's why I put the .ecore files into src/main/resources and changed the url locating line. However with that explanation, I'm seeing the difference between the getClass().getResource("_3.ecore") and my modification which reads getClass().getResource("/_3.ecore"). So i just recreated the directory structure in the resources folder and now the .ecore files are getting exported to the correct location in the jar.

>> For further experimentation I took a look at the _3Example.java file
>> generated by the model code. It think the relevant parts our
>> something like this:
>>
>> // Create a resource set to hold the resources.
>> //
>> ResourceSet resourceSet = new ResourceSetImpl();
>> // Register the appropriate resource factory to handle
>> all file extensions.
>> //
>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>> new _3ResourceFactoryImpl());
>>
>> // Register the package to ensure it is available during loading.
>> //
>> resourceSet.getPackageRegistry().put
>> (_3Package.eNS_URI, _3Package.eINSTANCE);
>> // Had to add this line, otherwise it said something like
>> "version" not found.
>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
>> new XMIResourceFactoryImpl());
>But the generated code explicitly uses

>Resource resource = new
>EcoreResourceFactoryImpl().createResource(uri);
Ah I see what you are mentioning. Judging by the name I would assume this is what I should be using to read the .ecore modules in and it can handle the XMI stuff automatically. However, when I remove the ecore->XMIResourceFactoryImpl mapping I get the following stack trace:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'version' not found. (file:/valid/path/to/_3.ecore, 3, 120)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at emf.test._3Example.main(_3Example.java:88)
Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'version' not found. (file:valid/path/to/_3.ecore, 3, 120)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
	at org.eclipse.emf.ecore.xmi.impl.SAXXMLHandler.handleObjectAttribs(SAXXMLHandler.java:77)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1292)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:332)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	... 2 more

Explicitly registering the ecore models with the EcoreResourceFactoryImpl(instead of the XMIresourceFactoryImpl also works. Could this be because I generated my model from some XSD files? I'm also pointing the argument in the URL to my .ecore file and not an instance of an XML file corresponding to that schema as I don't currently have one. However, the test class has no problem with loading this and detects no validation errors when it loads in the main project emf project. When add a dependency on this jar and move the same file up into the new project I encounter the Feature 'XMI' not found errors.
>>
>> File file = new File(args[i]);
>> URI uri = file.isFile() ?
>> URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
>>
>> try {
>> // Demand load resource for this file.
>> //
>> Resource resource = resourceSet.getResource(uri,
>> true);
>> System.out.println("Loaded " + uri);
>>
>>
>> This code failed in the original generated test package because it
>> couldn't find the ecore files. That makes sense as I slightly
>> modified the loadPackage() method and it failed with the "Missing
>> serialized package" message. No problems here.
>It's hard to comment on slight modifications... Without modification it
>just works for me.
I completely understand that. The modification I was referring to was the one I mentioned above about changing the line in loadPackage to URL url = getClass().getResource("/" + packageFilename). I've removed this now as the .ecore files are sent to the right place.
>
>> I copied the same class into the next project that depends directly on
>> my generated modules. I was able to successfully load the resource
>> without any problems.
>> I then copied the class into a project one level higher(where I really
>> need it to be). This is where it seems to fail on the
>> _3Package.eInstance call. I attempted to add this line
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
>> new XMIResourceFactoryImpl());
>Given the code explicitly uses EcoreResourceFactoryImpl it's hard to
>understand why a registration is required...
I think at this point i was just trying to get things to make things work for me and figured maybe I had dropped out of an Eclipse instance somehow and was following the example for a standalone project in the FAQ.
>>
>> before the call as I believe it registers the ecore files to the
>> XMIResourceFactoryImpl globally. It gets into loadPackage and fails
>> while attempting to read the model.
>> I'm thinking maybe I'm losing some sort of configuration option
>> somewhere as I go up the chain, but I'm not real sure what to look for.
>> Thanks again for your help!
>I can't comment on your slight modifications without seeing them.
>Without any modifications to the generated code, which exactly fails?
So I reverted back all of my modifications and have the .ecore files where they belong and am attempting to simplify some things.

I've got my base model classes in a jar called emf.jar. I have a second project called emf_to_business_objects.jar that depends on emf.jar. I've made a very simple test class that just has the following line in its main
_3Package.eINSTANCE.eClass();
. This works as expected in this project and if I open my debugger I get a populated EClass object.

If I have a third project, and make either the emf.jar or emf_to_business_objects.jar dependencies and attempt to run the same line of code I get a very large exception chain that looks like this:
Exception in thread "main" java.lang.ExceptionInInitializerError
	at net.opengis.ows._1.impl._1PackageImpl.init(_1PackageImpl.java:574)
	at net.opengis.ows._1._1Package.<clinit>(_1Package.java:280)
	at net.opengis.fes._2.impl._2PackageImpl.init(_2PackageImpl.java:777)
	at net.opengis.fes._2._2Package.<clinit>(_2Package.java:356)
	atnet.opengis.gml._3.impl._3PackageImpl.init(_3PackageImpl.java:320)
	at net.opengis.gml._3._3Package.<clinit>(_3Package.java:68)
	at test._3Example.main(_3Example.java:28)
Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
	at net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29965)
	at net.opengis.wfs._2.impl._2PackageImpl.init(_2PackageImpl.java:773)
	at net.opengis.wfs._2._2Package.<clinit>(_2Package.java:366)
	... 39 more
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
	at net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29962)
	... 41 more
Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeature(XMIHandler.java:145)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
	at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:74)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)


So I guess what's really confusing me is why the same block of code is working in one project, but not the other when they are sharing the same underlying EMF model dependency.
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1565844 is a reply to message #1564567] Thu, 15 January 2015 14:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Justin,

Comments below.

On 14/01/2015 10:46 PM, Justin Field wrote:
> Thanks again for your responses Ed! I've commented a bit more below.
>
>>> Ed, thanks for your help! That code block you mentioned before with
>>> the call to loadPackage() is where I am failing on the call to
>>> resouce.load(null). I have modified the line
>>> URL url = getClass().getResource(packageFilename); to be URL url =
>>> getClass().getResource("/" + packageFilename); so that I could place
>>> the .ecore files in the resource files as I was having problems
>>> determining where exactly to put them in the subproject without that.
>
>> It should be relative to the class; normally the builder will copy
>> such files to the bin folder and when you publish to a jar it should
>> end up in the jar in the same folder as the package class. Again,
>> this just works out of the box for me...
> Hmm, my main EMF project is actually setup as a maven project that by
> a former employee, so I'm not really sure how things have potentially
> changed from the default.
So it's not obvious to me how Maven builds; perhaps it doesn't
automatically copy the *.ecore as a resource to the corresponding folder
where the .class file for each .java file appears.
> I don't have a bin directory
Certainly when developing in Eclipse you do, though it's generally hidden.
> so that's why I put the .ecore files into src/main/resources and
> changed the url locating line.
It's all kind of questionable. It very normal/common to put resources
in the folder where the .class file is and load relative to that.
> However with that explanation, I'm seeing the difference between the
> getClass().getResource("_3.ecore") and my modification which reads
> getClass().getResource("/_3.ecore").
How does that relate to src/main/resources? Where do those end up at
runtime? /_3.ecore implies to me it's somewhere in the root of some
jar/folder...
> So i just recreated the directory structure in the resources folder
> and now the .ecore files are getting exported to the correct location
> in the jar.
>>> For further experimentation I took a look at the _3Example.java file
>>> generated by the model code. It think the relevant parts our
>>> something like this:
>>>
>>> // Create a resource set to hold the resources.
>>> //
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> // Register the appropriate resource factory to handle all file
>>> extensions.
>>> //
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
>>> (Resource.Factory.Registry.DEFAULT_EXTENSION, new
>>> _3ResourceFactoryImpl());
>>>
>>> // Register the package to ensure it is available during loading.
>>> //
>>> resourceSet.getPackageRegistry().put
>>> (_3Package.eNS_URI, _3Package.eINSTANCE);
>>> // Had to add this line, otherwise it said something like "version"
>>> not found.
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
>>> new XMIResourceFactoryImpl());
>> But the generated code explicitly uses
>
>> Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
> Ah I see what you are mentioning. Judging by the name I would assume
> this is what I should be using to read the .ecore modules in and it
> can handle the XMI stuff automatically.
Yes.
> However, when I remove the ecore->XMIResourceFactoryImpl mapping I get
> the following stack trace:
>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'version'
> not found. (file:/valid/path/to/_3.ecore, 3, 120)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
How does this relate to the generated loadPackage method? I don't see
that on the stack. Here it appears you're trying to load _3.ecore
into a resource set, but that's not what the generated loadPackage
method is doing...
> at emf.test._3Example.main(_3Example.java:88)
> Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'version' not found. (file:valid/path/to/_3.ecore, 3, 120)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
> at
> org.eclipse.emf.ecore.xmi.impl.SAXXMLHandler.handleObjectAttribs(SAXXMLHandler.java:77)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
> at
> com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1292)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:332)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
> ... 2 more
>
> Explicitly registering the ecore models with the
> EcoreResourceFactoryImpl(instead of the XMIresourceFactoryImpl also works.
No doubt, but why are you loading _3.ecore into a resource set?
> Could this be because I generated my model from some XSD files? I'm
> also pointing the argument in the URL to my .ecore file
I can't parse this statement? What do you mean by "pointing the
argument in the URL"?
> and not an instance of an XML file corresponding to that schema as I
> don't currently have one. However, the test class has no problem with
> loading this and detects no validation errors when it loads in the
> main project emf project. When add a dependency on this jar and move
> the same file up into the new project I encounter the Feature 'XMI'
> not found errors.
>>>
>>> File file = new File(args[i]);
>>> URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath())
>>> : URI.createURI(args[i]);
>>>
>>> try {
>>> // Demand load resource for this file.
>>> //
>>> Resource resource = resourceSet.getResource(uri, true);
>>> System.out.println("Loaded " + uri);
>>>
>>>
>>> This code failed in the original generated test package because it
>>> couldn't find the ecore files. That makes sense as I slightly
>>> modified the loadPackage() method and it failed with the "Missing
>>> serialized package" message. No problems here.
>> It's hard to comment on slight modifications... Without modification
>> it just works for me.
> I completely understand that. The modification I was referring to was
> the one I mentioned above about changing the line in loadPackage to
> URL url = getClass().getResource("/" + packageFilename). I've removed
> this now as the .ecore files are sent to the right place.
Why isn't that in your stack trace? What value are you getting for this
URL?
>>
>>> I copied the same class into the next project that depends directly
>>> on my generated modules. I was able to successfully load the
>>> resource without any problems.
>>> I then copied the class into a project one level higher(where I
>>> really need it to be). This is where it seems to fail on the
>>> _3Package.eInstance call. I attempted to add this line
>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
>>> new XMIResourceFactoryImpl());
>> Given the code explicitly uses EcoreResourceFactoryImpl it's hard to
>> understand why a registration is required...
> I think at this point i was just trying to get things to make things
> work for me and figured maybe I had dropped out of an Eclipse instance
> somehow and was following the example for a standalone project in the
> FAQ.
>>>
>>> before the call as I believe it registers the ecore files to the
>>> XMIResourceFactoryImpl globally. It gets into loadPackage and fails
>>> while attempting to read the model.
>>> I'm thinking maybe I'm losing some sort of configuration option
>>> somewhere as I go up the chain, but I'm not real sure what to look for.
>>> Thanks again for your help!
>> I can't comment on your slight modifications without seeing them.
>> Without any modifications to the generated code, which exactly fails?
> So I reverted back all of my modifications and have the .ecore files
> where they belong and am attempting to simplify some things.
>
> I've got my base model classes in a jar called emf.jar. I have a
> second project called emf_to_business_objects.jar that depends on
> emf.jar. I've made a very simple test class that just has the
> following line in its main _3Package.eINSTANCE.eClass();. This works
> as expected in this project and if I open my debugger I get a
> populated EClass object.
> If I have a third project, and make either the emf.jar or
> emf_to_business_objects.jar dependencies and attempt to run the same
> line of code I get a very large exception chain that looks like this:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at net.opengis.ows._1.impl._1PackageImpl.init(_1PackageImpl.java:574)
> at net.opengis.ows._1._1Package.<clinit>(_1Package.java:280)
> at net.opengis.fes._2.impl._2PackageImpl.init(_2PackageImpl.java:777)
> at net.opengis.fes._2._2Package.<clinit>(_2Package.java:356)
> atnet.opengis.gml._3.impl._3PackageImpl.init(_3PackageImpl.java:320)
> at net.opengis.gml._3._3Package.<clinit>(_3Package.java:68)
> at test._3Example.main(_3Example.java:28)
But now you have package dependencies and there seems to be some
implication here that _3 depends on _2 and _1. Where are those?
> Caused by: org.eclipse.emf.common.util.WrappedException:
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
You've mentioned jars. Is the *.ecore in a jar? Why isn't the URL
pointing into the jar?
> at
> net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29965)
>
> at net.opengis.wfs._2.impl._2PackageImpl.init(_2PackageImpl.java:773)
> at net.opengis.wfs._2._2Package.<clinit>(_2Package.java:366)
> ... 39 more
> Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException:
> Feature 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
> at
> net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29962)
> ... 41 more
> Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeature(XMIHandler.java:145)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
> at
> org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:74)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
> at
> org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
> at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
>
>
> So I guess what's really confusing me is why the same block of code is
> working in one project, but not the other when they are sharing the
> same underlying EMF model dependency.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1566268 is a reply to message #1565844] Thu, 15 January 2015 19:31 Go to previous messageGo to next message
Justin Field is currently offline Justin FieldFriend
Messages: 7
Registered: July 2014
Junior Member
Ed,
I've added some more comments below. With that being said, I think it might be a good idea for me to just start a new project as one of the EMF project types and remove all the maven stuff and regenerate my module. I think that's where a good portion of the disconnect is occurring.

Once again thank you for all of your responses!

>> Thanks again for your responses Ed! I've commented a bit more below.
>>
>>>> Ed, thanks for your help! That code block you mentioned before with
>>>> the call to loadPackage() is where I am failing on the call to
>>>> resouce.load(null). I have modified the line
>>>> URL url = getClass().getResource(packageFilename); to be URL url =
>>>> getClass().getResource("/" + packageFilename); so that I could place
>>>> the .ecore files in the resource files as I was having problems
>>>> determining where exactly to put them in the subproject without that.
>>
>>> It should be relative to the class; normally the builder will copy
>>> such files to the bin folder and when you publish to a jar it should
>>> end up in the jar in the same folder as the package class. Again,
>>> this just works out of the box for me...
>> Hmm, my main EMF project is actually setup as a maven project that by
>> a former employee, so I'm not really sure how things have potentially
>> changed from the default.
>So it's not obvious to me how Maven builds; perhaps it doesn't
>automatically copy the *.ecore as a resource to the corresponding folder
>where the .class file for each .java file appears.
It doesn't seem to do this automatically when it builds. With maven we are building not to bin, but to target/classes by default.
>> I don't have a bin directory
>Certainly when developing in Eclipse you do, though it's generally hidden.
I know I have a directory called "bin" with a standard eclipse setup. However, with a default maven project we are setting the output folder to target/classes. I've got no directory called "bin" even if I navigate through Windows explorer to my project in the workspace. There's one in main eclipse where all of the eclipse plugins are located, but I don't think that's what you are talking about.
>> so that's why I put the .ecore files into src/main/resources and
>> changed the url locating line.
>It's all kind of questionable. It very normal/common to put resources
>in the folder where the .class file is and load relative to that.
Understood, I've removed that code.
>> However with that explanation, I'm seeing the difference between the
>> getClass().getResource("_3.ecore") and my modification which reads
>> getClass().getResource("/_3.ecore").
>How does that relate to src/main/resources? Where do those end up at
>runtime? /_3.ecore implies to me it's somewhere in the root of some
>jar/folder...
This is another maven thing. So by default anything put in src/main/resources is dumped into the root directory of your classpath in your jar/folder. A coworker informed me that if I recreate the folder structure of the classes under
src/main/resources then the .ecore's files are placed where I want them to be. So in this instance, my _3.ecore model is placed in src/main/resources/net/opengis/gml/_3/impl. Then when the jar is created they are placed relative to the _3PackageImpl class and loadPackage doesn't die out with a "Missing serialized package" message.
>> So i just recreated the directory structure in the resources folder
>> and now the .ecore files are getting exported to the correct location
>> in the jar.
>>>> For further experimentation I took a look at the _3Example.java file
>>>> generated by the model code. It think the relevant parts our
>>>> something like this:
>>>>
>>>> // Create a resource set to hold the resources.
>>>> //
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> // Register the appropriate resource factory to handle all file
>>>> extensions.
>>>> //
>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION, new
>>>> _3ResourceFactoryImpl());
>>>>
>>>> // Register the package to ensure it is available during loading.
>>>> //
>>>> resourceSet.getPackageRegistry().put
>>>> (_3Package.eNS_URI, _3Package.eINSTANCE);
>>>> // Had to add this line, otherwise it said something like "version"
>>>> not found.
>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
>>>> new XMIResourceFactoryImpl());
>>> But the generated code explicitly uses
>>
>>> Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
>> Ah I see what you are mentioning. Judging by the name I would assume
>> this is what I should be using to read the .ecore modules in and it
>> can handle the XMI stuff automatically.
>Yes.
>> However, when I remove the ecore->XMIResourceFactoryImpl mapping I get
>> the following stack trace:
>>
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
>> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'version'
>> not found. (file:/valid/path/to/_3.ecore, 3, 120)
>>at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
>How does this relate to the generated loadPackage method? I don't see
>that on the stack. Here it appears you're trying to load _3.ecore
>into a resource set, but that's not what the generated loadPackage
>method is doing...
I don't think it really does. Here I was just trying to replicate the behavior from the test class in another project. I figured I should be able to read the _3.ecore files into the resource set and it was failing with the "Feature 'version" not found message". Looking on the forums, it appeared that this could occur when attempting to read in an XMI resource with an XML file(or I might have that backwards). Thus, I explicitly mapped my .ecore files to either and XMI/EcoreResourceFactoryImpl to guarantee that they were using one or the other. Both allowed me to get past this exception.
>> at emf.test._3Example.main(_3Example.java:88)
>> Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>> 'version' not found. (file:valid/path/to/_3.ecore, 3, 120)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
>> at
>> org.eclipse.emf.ecore.xmi.impl.SAXXMLHandler.handleObjectAttribs(SAXXMLHandler.java:77)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
>> at
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
>> at
>> com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1292)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
>> at
>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
>> at
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
>> at
>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
>> at
>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:332)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
>> ... 2 more
>>
>> Explicitly registering the ecore models with the
>> EcoreResourceFactoryImpl(instead of the XMIresourceFactoryImpl also works.
>No doubt, but why are you loading _3.ecore into a resource set?
I don't actually intend to do this in the program, but I figured my issue was occurring when attempting to parse/register the model, so I was trying to see if I could just load it directly without any issues.
>> Could this be because I generated my model from some XSD files? I'm
>> also pointing the argument in the URL to my .ecore file
>I can't parse this statement? What do you mean by "pointing the
>argument in the URL"?
Ah sorry, I just mean that my argument to the main in the test generated code is a path to a .ecore file. I get the feeling the original intention of the *Example.java files in the test project would be to pass in a path to a .xml file that corresponds to the model in the package you've generated.
>> and not an instance of an XML file corresponding to that schema as I
>> don't currently have one. However, the test class has no problem with
>> loading this and detects no validation errors when it loads in the
>> main project emf project. When add a dependency on this jar and move
>>the same file up into the new project I encounter the Feature 'XMI'
>> not found errors.
>>>>
>>>> File file = new File(args[i]);
>>>> URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath())
>>>> : URI.createURI(args[i]);
>>>>
>>>> try {
>>>> // Demand load resource for this file.
>>>> //
>>>> Resource resource = resourceSet.getResource(uri, true);
>>>> System.out.println("Loaded " + uri);
>>>>
>>>>
>>>> This code failed in the original generated test package because it
>>>> couldn't find the ecore files. That makes sense as I slightly
>>>> modified the loadPackage() method and it failed with the "Missing
>>>> serialized package" message. No problems here.
>>> It's hard to comment on slight modifications... Without modification
>>> it just works for me.
>>I completely understand that. The modification I was referring to was
>> the one I mentioned above about changing the line in loadPackage to
>> URL url = getClass().getResource("/" + packageFilename). I've removed
>> this now as the .ecore files are sent to the right place.
>Why isn't that in your stack trace? What value are you getting for this
>URL?
I removed this line once I figured out how to get the .ecore models correctly relative to the class. Originally, when the models weren't relative to the class, I was getting null on this call. Thus, I placed all of the models at root and made this change. This has all been reverted now!
>>>
>>>> I copied the same class into the next project that depends directly
>>>> on my generated modules. I was able to successfully load the
>>>> resource without any problems.
>>>> I then copied the class into a project one level higher(where I
>>>> really need it to be). This is where it seems to fail on the
>>>> _3Package.eInstance call. I attempted to add this line
>>>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
>>>> new XMIResourceFactoryImpl());
>>> Given the code explicitly uses EcoreResourceFactoryImpl it's hard to
>>> understand why a registration is required...
>> I think at this point i was just trying to get things to make things
>> work for me and figured maybe I had dropped out of an Eclipse instance
>> somehow and was following the example for a standalone project in the
>> FAQ.
>>>>
>>>> before the call as I believe it registers the ecore files to the
>>>> XMIResourceFactoryImpl globally. It gets into loadPackage and fails
>>>> while attempting to read the model.
>>>> I'm thinking maybe I'm losing some sort of configuration option
>>>> somewhere as I go up the chain, but I'm not real sure what to look for.
>>>> Thanks again for your help!
>>> I can't comment on your slight modifications without seeing them.
>>> Without any modifications to the generated code, which exactly fails?
>> So I reverted back all of my modifications and have the .ecore files
>> where they belong and am attempting to simplify some things.
>>
>> I've got my base model classes in a jar called emf.jar. I have a
>> second project called emf_to_business_objects.jar that depends on
>> emf.jar. I've made a very simple test class that just has the
>> following line in its main _3Package.eINSTANCE.eClass();. This works
>> as expected in this project and if I open my debugger I get a
>> populated EClass object.
>>If I have a third project, and make either the emf.jar or
>> emf_to_business_objects.jar dependencies and attempt to run the same
>> line of code I get a very large exception chain that looks like this:
>>
>> Exception in thread "main" java.lang.ExceptionInInitializerError
>> at net.opengis.ows._1.impl._1PackageImpl.init(_1PackageImpl.java:574)
>> at net.opengis.ows._1._1Package.<clinit>(_1Package.java:280)
>> at net.opengis.fes._2.impl._2PackageImpl.init(_2PackageImpl.java:777)
>> at net.opengis.fes._2._2Package.<clinit>(_2Package.java:356)
>> atnet.opengis.gml._3.impl._3PackageImpl.init(_3PackageImpl.java:320)
>> at net.opengis.gml._3._3Package.<clinit>(_3Package.java:68)
>> at test._3Example.main(_3Example.java:28)
>But now you have package dependencies and there seems to be some
>implication here that _3 depends on _2 and _1. Where are those?
Yup, I've trimmed down the stacktrace a bit because I've got about 15 packages or so that depend on each other in various ways. I have placed all of the .ecore files in the same folder as the modelNameImplFactory.class files now. Some of them are smaller and have "Initialize by loading" set to false, so they can probably be removed, but I wasn't 100% sure on that so I put them in as well.
>> Caused by: org.eclipse.emf.common.util.WrappedException:
>> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
>> 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
>You've mentioned jars. Is the *.ecore in a jar? Why isn't the URL
>pointing into the jar?
Ah, not this was something I didn't notice and is actually kind of cool. When you build with maven(at least the standard behavior) is to place everything into a folder called target->classes. When you deploy a jar using one of the maven tasks it takes target->classes, wraps it up, and sends it to a jar repository.

One of the cool things you can do with maven and eclipse is turn on workspace dependency resolution. What this does is allow you to run directly off a project's target->classes directory if that project is in your workspace. It's very similar as depending on another project in eclipse via the "Java Build Path" entry.

So I forgot I had that feature on and was treating the local project as a jar. Deploying the jar to my jar repo and closing the project changed the URL line reading Feature 'xmi' not found. (jar:file:/C:/m2repo/net/opengis/gml/1.0.1-SNAPSHOT/gml-1.0.1-SNAPSHOT.jar!/net/opengis/gml/_3/impl/_3.ecore
>> at
>> net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29965)
>>
>> at net.opengis.wfs._2.impl._2PackageImpl.init(_2PackageImpl.java:773)
>> at net.opengis.wfs._2._2Package.<clinit>(_2Package.java:366)
>> ... 39 more
>> Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException:
>> Feature 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
>> at
>> net.opengis.gml._3.impl._3PackageImpl.loadPackage(_3PackageImpl.java:29962)
>> ... 41 more
>> Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>> 'xmi' not found. (file:valid/path/to/_3.ecore, 3, 120)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeature(XMLHandler.java:2027)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleUnknownFeature(XMLHandler.java:1991)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.handleUnknownFeature(XMIHandler.java:145)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2743)
>> at
>> org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:74)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2229)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
>> at
>> org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
>> at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown
>> Source)
>> at
>> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
>> Source)
>> at
>> org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown
>> Source)
>> at
>> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
>> Source)
>> at
>> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
>> Source)
>> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>> at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>> at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
>>
>>
>> So I guess what's really confusing me is why the same block of code is
>> working in one project, but not the other when they are sharing the
>> same underlying EMF model dependency.
Re: [EMF] Feature 'XMI' not found when error message when loading large ecore models [message #1566529 is a reply to message #1566268] Thu, 15 January 2015 23:03 Go to previous message
Justin Field is currently offline Justin FieldFriend
Messages: 7
Registered: July 2014
Junior Member
Alright I just figured out why I was getting different behavior across two different projects. It turns out the highest level project also had a dependency on an ancient version(2.4.0) of the xerces XML library.

Bumping this up to the latest version removed the "Feature 'XMI' not found" error messages.

Thanks again for all of your help!
Previous Topic:create dynamic instances from an .ecore
Next Topic:Annotated Java import missing
Goto Forum:
  


Current Time: Thu Mar 28 21:11:53 GMT 2024

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

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

Back to the top