Friday, June 11, 2010

Package with URI '*' not found

I believe most of the users of EMF (developers or adopters alike) have seen this message at least once; and most probably wondered what was going on :).

This error message indicates that the package which NsURI is '*' hasn't been registered in the Package registry. Most of the time, that means you either a) launched your program standalone and didn't register the package correctly or b) you haven't installed the plug-in that provides that metamodel.

With Acceleo, encountering this exception is even more likely than normal, as the launch configuration for our generations allow for both standalone or plug-in generations. Selecting standalone without registering the needed package will inevitably lead to this error.

Solving it is easy : it is a matter of registering the needed packages (and, optionally, resource factories). How is it done? Here is the most classic example with UML :

Package with uri 'http://www.eclipse.org/uml2/2.1.0/UML' not found.

What do I need to do for my UML model to be loadable :

EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE
.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);


The same goes for every metamodel you might need, simply change UMLPackage by XxxPackage according to your metamodel. The Resource Factory is mandatory for UML, but your metamodel might not need one; simply ignore this line if you don't have a custom factory.

You need these two lines to be before the point where your model is loaded. For Acceleo, this is done in the generated Java launcher : simply change the implementation of the registerPackages and registerResourceFactories method to add these needed lines.

1 comment:

  1. Hi, I'm new to Acceleo. If I want to run acceleo from .java, for ex, Generated.java --> main() instead of running it from generated.mtl, can you tell me what must I do ?
    I always got these errors:
    Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'file:/home/nxhoaf/workspaceModelling/org.eclipse.acceleo.module.firstGp/model/AvoidObstaclesWithLaserModif.uml'; a registered resource factory is needed
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
    at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:358)
    at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:451)
    at org.eclipse.acceleo.module.firstGp.common.Generate.(Generate.java:97)
    at org.eclipse.acceleo.module.firstGp.common.Generate.main(Generate.java:161)

    ReplyDelete