加载资源时出现java“需要注册工厂”异常
我得到以下例外情况:
java.lang.RuntimeException: Cannot create a resource for 'file:/home/my_conf.xml'; a registered resource factory is needed
“爆炸”代码如下所示,并在以下位置停止:resource = resourceSet.....
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = null;
File f = new File(filename);
URI uri = URI.createFileURI(f.getAbsolutePath());
if (!f.exists()) {
throw new Exception(filename + " does not exist");
} else {
resource = resourceSet.getResource(uri, true);
mapPrepConfiguration = (MapPrepConfiguration) resource.getContents().get(0);
}
有人有线索吗
# 1 楼答案
如果在独立模式下运行,则必须手动将工厂注册到资源集工厂注册表
在创建资源集实例后添加以下行:
请参阅http://wiki.eclipse.org/EMF-FAQ#How_do_I_use_EMF_in_standalone_applications_.28such_as_an_ordinary_main.29.3F
对于“未找到包裹”问题,根据您的情况,有两种可能性:
在前面的代码中,您必须先以编程方式从ecore模型中检索EPackage