简体   繁体   中英

Ecore EMF PackageNotFoundException

I have to work with a project I didn't wrote myself. It uses Ecore EMF (I have no experience with this) and I can't figure out how to solve this error:

At some point the program loads a .xmi file with this function: org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI()

And this results in this error: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'platform:/plugin/Animals/model/Animals.ecore' not found. (file:/C:/Users/model917.xmi, 2, 193)

It seems like the file model917.xmi exists and is not the origin of this error. I think the problem is caused because the Animals.ecore file is not found. In the model917.xmi file I found this statement:

xmlns: Animals ="platform:/plugin/Animals/model/Animals.ecore

So I think the model in file model917.xmi uses another model defined in Animals.ecore which can't be found and causes the error.

I have access to the Animals.ecore file and found out that EMF/ecore uses something like a registry to find such files. So it seems like I have to add the Animals.ecore file to this registry and I found some answers online which didn't work and I run out of ideas what to try next. Can someone give me an easy way to register this file so it will be found? I am using Eclipse if this is relevant/maybe there is an easy way to do it with Eclipse.

Usually, EMF-based softwares should rely on the so-called "namespace URI" (nsURI) of EPackages, which are usually of the form "http://foo/bar/Animals".

"http://foo/bar/Animals" should be registered in the EMF Registry and dispatch depending on your actual runtime situation to a URI that looks like "platform:/plugin/bar.foo/Animals.ecore" (when file Animals.ecore is deployed in an Eclipse plugin for an Eclipse-based application), or "platform:/resource/bar.foo/Animals.ecore" (when file Animals.ecore is deployed in the workspace of the running Eclipse-based application) or even "file:///path/to/Animals.ecore" (anywhere on the filesystem). Technically you can use any of those URI forms as long as they are correctly resolved at runtime, but you must understand that not all URIs make sense in all contexts, for instance "platform:/" URIs only make sense in Eclipse-based context. nsURIs are supposed to be resolveable in all contexts (thanks to the registry!)

Is your code meant to be running in the context of an Eclipse-based application ? Then the project containing Animals.ecore should be deployed as a plugin, and I am guessing it is currently not. Is your code meant to be standalone? Then the reference in your xmi file, to the ecore file, should not be of the form "platform:/..." but rather of the form "http://foo/bar/Animals" (the nsURI of the EPackage that is the root element of Animals.ecore)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM