我知道有几个关于这个主题的 QnA。我尝试了很多解决方案,我总是遇到同样的错误。
我的代码结构如下:
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.getResource(URI.createURI("model/List.xmi"), true);
resource.load(Collections.EMPTY_MAP);
EObject root = resource.getContents().get(0);
错误:
线程“主”org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException 中的异常:org.eclipse.emf.ecore.xmi.PackageNotFoundException:找不到带有 uri 'List' 的包。(file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi, 6, 40) at org.eclipse.emf。 ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319) 在 org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278) 在 org.eclipse.emf.ecore.resource。 impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406) at com.unitbilisim.research.transformation.ConvertEcore2Graph.main(ConvertEcore2Graph.java:61) 原因:org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri ' 未找到列表。(file:///C:/Users/2/My%20Repository/UNIT%20Research%20and%20Development/com.unitbilisim.research.transformation/model/List.xmi, 6, 40) at org.eclipse.emf。 ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625) 在 org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458) 在 org.eclipse.emf.ecore.xmi。 impl.XMLHandler.createObjectByType(XMLHandler.java:1335) 在 org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504) 在 org.eclipse.emf.ecore.xmi.impl.XMLHandler。 processElement(XMLHandler.java:1026) 在 org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77) 在 org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler. java:1008) 在 org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:
“未找到带有 uri 的包”是什么意思?我可以直接读取 xmi 文件还是需要将其解析为 xml 文件?
我也试过这个-> https://stackoverflow.com/a/4615965/1604503
XMIResource resource = new XMIResourceImpl(URI.createURI("model/List.xmi"));
resource.load(null);
System.out.println( resource.getContents().get(0) );
PackageNotFoundEx。和 Reource$IOWrappedEx。再次 :(
请帮忙
亲切的问候