Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to run Acceleo from java file
[Acceleo] How to run Acceleo from java file [message #769914] Thu, 22 December 2011 22:22 Go to next message
nxhoaf  is currently offline 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 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane Begaudeau
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

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 #870459 is a reply to message #774107] Tue, 08 May 2012 10:42 Go to previous messageGo to next message
Luc De Graef is currently offline Luc De Graef
Messages: 7
Registered: January 2011
Junior Member
Hello,

The example code in the generated java class is working for UML.
But I have created my own metamodel (not UML)

/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore

The java launcher is started with the 2 arguments:
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi"
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator"

Without any adaptations, I get a java.lang.RuntimeException:

Cannot create a resource for 'file:/D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi'; a registered resource factory is needed
at ...impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
at ....utils.ModelUtils.load(ModelUtils.java:348)
at ... .AbstractAcceleoGenerator.initialize(

I tried the adaptations in registerPackages(), but what do we need to specify as second parameter?
"UMLPackage" is not found as a class, and it is probably not what we need to specify...

resourceSet.getPackageRegistry().put("/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore", UMLPackage.eINSTANCE);

Thanks,

Luc
Re: [Acceleo] How to run Acceleo from java file [message #870460 is a reply to message #774107] Tue, 08 May 2012 10:42 Go to previous messageGo to next message
Luc De Graef is currently offline Luc De Graef
Messages: 7
Registered: January 2011
Junior Member
Hello,

The example code in the generated java class is working for UML.
But I have created my own metamodel (not UML)

/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore

The java launcher is started with the 2 arguments:
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi"
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator"

Without any adaptations, I get a java.lang.RuntimeException:

Cannot create a resource for 'file:/D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi'; a registered resource factory is needed
at ...impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
at ....utils.ModelUtils.load(ModelUtils.java:348)
at ... .AbstractAcceleoGenerator.initialize(

I tried the adaptations in registerPackages(), but what do we need to specify as second parameter?
"UMLPackage" is not found as a class, and it is probably not what we need to specify...

resourceSet.getPackageRegistry().put("/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore", UMLPackage.eINSTANCE);

Thanks,

Luc
Re: [Acceleo] How to run Acceleo from java file [message #870461 is a reply to message #774107] Tue, 08 May 2012 10:43 Go to previous messageGo to next message
Luc De Graef is currently offline Luc De Graef
Messages: 7
Registered: January 2011
Junior Member
Hello,

The example code in the generated java class is working for UML.
But I have created my own metamodel (not UML)

/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore

The java launcher is started with the 2 arguments:
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi"
- "D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator"

Without any adaptations, I get a java.lang.RuntimeException:

Cannot create a resource for 'file:/D:/Workspaces/Eclipse/TOS/Tooling/MetaModelGenerator/model/TruckProto.xmi'; a registered resource factory is needed
at ...impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
at ....utils.ModelUtils.load(ModelUtils.java:348)
at ... .AbstractAcceleoGenerator.initialize(

I tried the adaptations in registerPackages(), but what do we need to specify as second parameter?
"UMLPackage" is not found as a class, and it is probably not what we need to specify...

resourceSet.getPackageRegistry().put("/MetaModelGenerator/src/MetaModelGenerator/model/TosDataEntities.ecore", UMLPackage.eINSTANCE);

Thanks,

Luc
Re: [Acceleo] How to run Acceleo from java file [message #870633 is a reply to message #870461] Wed, 09 May 2012 07:20 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
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
Re: [Acceleo] How to run Acceleo from java file [message #870639 is a reply to message #870633] Wed, 09 May 2012 07:35 Go to previous messageGo to next message
Luc De Graef is currently offline Luc De Graef
Messages: 7
Registered: January 2011
Junior Member
Hello,

This seems to do part of the trick. Now the standalone generation works, but in the postgenerate, I get an exception


Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/resources/IWorkspaceRoot
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.postGenerate(AbstractAcceleoGenerator.java:567)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:195)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:158)
at MetaModelGenerator.main.GenerateDDL_Standalone.doGenerate(GenerateDDL_Standalone.java:192)
at MetaModelGenerator.main.GenerateDDL_Standalone.main(GenerateDDL_Standalone.java:155)

Any idea?

Regards,
Luc
Re: [Acceleo] How to run Acceleo from java file [message #870640 is a reply to message #870633] Wed, 09 May 2012 07:40 Go to previous message
Luc De Graef is currently offline Luc De Graef
Messages: 7
Registered: January 2011
Junior Member
Silly me,
I fixed the project setup and now it works.

Thanks for the help

Luc
Previous Topic:[Acceleo] Test for an undefined enumeration in OCL
Next Topic:Trying to load UTP 1.1 (xmi from OMG)
Goto Forum:
  


Current Time: Thu Oct 23 00:49:01 GMT 2014

Powered by FUDForum. Page generated in 0.02578 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software