"Package with uri 'null' not found" while loading XML file using EMF

1.1k Views Asked by At

I am trying to load an XML file using EMF and I am using the following code to do that in XMLArtefactAdapter.java:

constructor():

ResourceSet set = new ResourceSetImpl();
//registering factory
set.getResourceFactoryRegistry()
  .getExtensionToFactoryMap()
  .put
    (Resource.Factory.Registry.DEFAULT_EXTENSION,new XMLResourceFactoryImpl());

parse() method:

//parsing XML
try {
        String absolutePath = file.getAbsolutePath();
        URI uri = URI.createFileURI(absolutePath);
        Resource resource = resourceSet.createResource(uri);
        resource.load(Collections.EMPTY_MAP);

        System.out.println("LOADED");

    } catch (IOException e) {
        System.out.println(e.toString());
    }

I am executing this code fragment from my Main class:

Path path = Paths.get("C:\\Users\\Srijani\\Desktop\\book.xml");
XMLArtefactAdapter xmlAdapter = new XMLArtefactAdapter(path);
xmlAdapter.parse();

But, I get error while running this code.

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with uri 'null' not found. (file:/C:/Users/Srijani/Desktop/plugin.xml, 3, 9)

Please note the following: My Plugin.xml

<plugin>

   <extension point="org.eclipse.emf.ecore.generated_package">
      <!-- @generated simpletree -->
      <package
            uri="platform:/plugin/com.kaleidoscope.core.aux.simpletree/model/SimpleTree.ecore"
            class="SimpleTree.SimpletreePackage"
            genModel="model/simpletree.genmodel"/>
   </extension>

</plugin>

Any idea why this is happening? Thanks in Advance!

1

There are 1 best solutions below

0
Romain Bernard On

An EPackage uri is a kind of public identifier for your EPackage. It should not be an eclipse uri.

Usually, the namespace URI is an http url providing some basic informations about the EPackage provider, ePackage name and version. eg :

  <extension point="org.eclipse.emf.ecore.generated_package">
     <package
        uri="http://www.eclipse.org/emf/2002/Ecore"
        class="org.eclipse.emf.ecore.EcorePackage"
        genModel="model/Ecore.genmodel"/>
  </extension>

You should :

  1. change your EPackage nsUri with an identifier for your EPackage,
  2. regenerate the EMF code,
  3. and merge your plugin.xml and plugin.xml_gen files to synchronize your nsURI value.