“Registered factory needed” exception when loading resource

人盡茶涼 提交于 2019-12-05 18:02:49

If you are running in standalone mode, you will have to manually register the factories to your resource set factory registry.
Add the following line after the creation of your resource set instance:

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());

Please see http://wiki.eclipse.org/EMF-FAQ#How_do_I_use_EMF_in_standalone_applications_.28such_as_an_ordinary_main.29.3F

For the Package not found issue there is two possibilities depending of your case:

  • If you are using a static metamodel (a java implementation is generated from your ecore model), you only have to access the corresponding Package instance for it to be loaded and registered into the global EMF package registry.

YourPackage packageInstance = YourPackage.eInstance;

  • If you are using a dynamic metamodel (no java code generated), you have to register it manually.
resourceSet.getPackageRegistry().put(yourPackage.getNsURI(), yourPackage);

With the previous code, you will have to previously retrieve the EPackage from your ecore model programmatically.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!