[Acceleo] How to run Acceleo from java file [message #769914] |
Thu, 22 December 2011 22:22 |
nxhoaf Messages: 1 Registered: December 2011 |
Junior Member |
|
|
Hi,
Is there any way to run Acceleo from java file? I mean that, instead of using .mtl file, for ex, generated.mtl, I want to use Generated.java. The main function in this java file required 2 args: model and folder. When using generated.mtl, I used "/org.eclipse.acceleo.module.firstGp/model/model.uml" as input param for "Model" field and it worked for me. But when I tried main() in Generated.java with these 2 params:
model: model.uml
foldel: model
It seemed not to work, and here is the output:
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'model.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.<init>(Generate.java:90)
at org.eclipse.acceleo.module.firstGp.common.Generate.main(Generate.java:137)
So, can anyone tells me how must I do to run Acceleo from java file ?
I'm using Eclipse Modelling (Indigo) and Acceleo 3.2
[Updated on: Sat, 24 December 2011 13:27] Report message to a moderator
|
|
|
Re: [Acceleo] How to run Acceleo from java file [message #774107 is a reply to message #769914] |
Tue, 03 January 2012 09:22 |
|
Hi,
In order to load a ".uml" model, you need to "tell" EMF the necessary resource factory. If you look at the Java launcher generated by Acceleo, you need to add a resource factory in the method "registerResourceFactories" (this method contains an example for UML in a comment so in your case, you just need to remove the "//" before the example). You also need to change the "@generated" tag of this method to "@generated NOT" so that your changes do not get overwritten by a refresh of this Java launcher by Acceleo. You may need to register the UML metamodel next, if that's the case, you should have a look at the method "registerPackages" where another UML specific example is available.
Regards,
Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
|
|
|
|
|
|
Re: [Acceleo] How to run Acceleo from java file [message #870633 is a reply to message #870461] |
Wed, 09 May 2012 07:20 |
|
Hi Luc,
The example we provide as comment in the "registerResourceFactories" method is only aimed at "uml" files. In your case, the model you're trying to load is an XMI file. You thus need to register a factory against that extension. If you do not have your own resource (which I assume since it is the default), adding a line such as this in the method should do the trick :
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Laurent Goubet
Obeo
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07228 seconds