简体   繁体   English

Ecore EMF PackageNotFoundException

[英]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:它使用 Ecore EMF(我没有这方面的经验),我不知道如何解决这个错误:

At some point the program loads a .xmi file with this function: org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI()在某些时候,程序会使用以下函数加载 .xmi 文件: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.这导致了这个错误:org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'platform:/plugin/Animals/model/Animals.ecore' not found。 (file:/C:/Users/model917.xmi, 2, 193) (文件:/C:/Users/model917.xmi, 2, 193)

It seems like the file model917.xmi exists and is not the origin of this error.似乎文件 model917.xmi 存在并且不是此错误的根源。 I think the problem is caused because the Animals.ecore file is not found.我认为问题是由于找不到 Animals.ecore 文件引起的。 In the model917.xmi file I found this statement:在 model917.xmi 文件中,我发现了这个语句:

xmlns: Animals ="platform:/plugin/Animals/model/Animals.ecore xmlns:动物=“平台:/插件/动物/模型/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.所以我认为文件model917.xmi 中的模型使用了Animals.ecore 中定义的另一个模型,该模型无法找到并导致错误。

I have access to the Animals.ecore file and found out that EMF/ecore uses something like a registry to find such files.我可以访问 Animals.ecore 文件并发现 EMF/ecore 使用类似于注册表的东西来查找此类文件。 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.所以看起来我必须将 Animals.ecore 文件添加到这个注册表中,我在网上找到了一些不起作用的答案,我想不出下一步该尝试什么。 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.如果这是相关的,我正在使用 Eclipse/也许有一种简单的方法可以使用 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".通常,基于 EMF 的软件应该依赖于 EPackages 所谓的“命名空间 URI”(nsURI),其格式通常为“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). “http://foo/bar/Animals”应该在 EMF 注册表中注册并根据您的实际运行时情况分派到一个类似于“platform:/plugin/bar.foo/Animals.ecore”的 URI(当文件 Animals .ecore 部署在基于 Eclipse 的应用程序的 Eclipse 插件中),或“platform:/resource/bar.foo/Animals.ecore”(当文件 Animals.ecore 部署在运行的基于 Eclipse 的应用程序的工作区中时)甚至“file:///path/to/Animals.ecore”(文件系统上的任何地方)。 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.从技术上讲,您可以使用任何这些 URI 形式,只要它们在运行时正确解析,但您必须了解并非所有 URI 在所有上下文中都有意义,例如“平台:/”URI 仅在基于 Eclipse 的上下文中有意义。 nsURIs are supposed to be resolveable in all contexts (thanks to the registry!) nsURI 应该在所有上下文中都可以解析(感谢注册表!)

Is your code meant to be running in the context of an Eclipse-based application ?您的代码是否打算在基于 Eclipse 的应用程序的上下文中运行? Then the project containing Animals.ecore should be deployed as a plugin, and I am guessing it is currently not.然后应该将包含 Animals.ecore 的项目部署为插件,我猜目前还没有。 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)然后,您的 xmi 文件中对 ecore 文件的引用不应采用“platform:/...”形式,而应采用“http://foo/bar/Animals”形式(EPackage 的 nsURI,是 Animals.ecore 的根元素)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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