2

I try to make generator from my custom metamodel. I created it by Obeo Designer - it is ecore metamodel.

So I create new Acceleo Project, choose my metamodel URI (http://org/model/ros) from "Runtime version" and try to run it.

But project can't run and i get exception:

Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://org/model/ros' not found. (file:/C:/Users/Jakub%20Kitaj/Downloads/ObeoDesigner-Community-8.1-win32.win32.x86/ObeoDesigner-Community/workspace/TestAcceleo/model/example.ros, 2, 120)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1335)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:78)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:190)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
... 6 more

I think i should set my custom metamodel but how can I do this?

EDIT:

I add this code line:
resourceSet.getPackageRegistry().put("http://org/model/ros", Package.class); but I get same error. http://org/model/ros is my metamodel nsUri and Package.class is instance of element from my metamodel object. :(

What can I do else? :(

kuba44
  • 1,838
  • 9
  • 34
  • 62

2 Answers2

0

What do you need to do for your UML model to be loadable is as below:

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.

Jaya
  • 111
  • 5
  • I add this code line: `resourceSet.getPackageRegistry().put("http://org/model/ros", Package.class);` but I get same error. `http://org/model/ros` is my metamodel nsUri and `Package.class` is instance of element from my metamodel object. :( What can I do else? :( – kuba44 Jun 17 '16 at 09:08
  • Have you changed the implementation of registerResourceFactories method? – Jaya Jun 21 '16 at 19:02
  • No, I made new Acceleo project by wizard and change only registerPackages method. I don't have a custom factory. – kuba44 Jun 22 '16 at 19:53
  • Only thing I can think of now is try resolving by adding an extension to your plugin.xml file: – Jaya Jun 23 '16 at 19:33
  • Hmm.. I don't have `plugin.xml` file in my project :( – kuba44 Jun 25 '16 at 00:24
0

Maybe you should compile your metamodel (using emf) first, then export it to a jar file, pasting it on the eclipse plugin folder and restarting your eclipse.

you can right click your .ecore model and click "new".. "other".. and find "Emf Generator Model", (next > next > load > next > finish ..) then you'll get a .genmodel file. with this file opened you click to the root element and click generate all, it will generate a set of projects. then you go to the process of exporting a plugin.. right click to your project and click "export.." > "Plug-in Development" > "Deployable plugins and fragments", go through all the process.. then copy the generated jar files and paste on the plugins folder inside of the eclipse installation folder and restart the eclipse.. as magic you'll have code completion from your metamodel :'D

Uisleandro
  • 31
  • 4