Jump to: navigation, search

Difference between revisions of "Acceleo/FAQ"

(UML profiles)
(Typing error with consequences)
Line 177: Line 177:
* moduleA.templateA
* moduleA.templateA
* moduleA.templateB
* moduleA.templateB
* moduleA.templateD (by calling super in moduleB.templateB)
* moduleA.templateD (by calling super in moduleB.templateD)
* moduleA.queryA
* moduleA.queryA
* moduleA.queryB
* moduleA.queryB

Revision as of 08:23, 18 December 2012

The Java launcher class is not generated

Acceleo generates and maintains the Java launcher for each Acceleo module with a main template. A main template is defined as a template with the following comment "[comment @main/]". You can create a main module by using the Acceleo Main Module wizard or by selecting "main template" in the regular Acceleo Module wizard. If you remove this comment, the Java launcher will not be synchronized anymore, if you change the metamodel used in your module, Acceleo will not register it in the Java launcher, etc.

My metamodel is not found by Acceleo

If you encounter the following errors in the Java launcher.

 a.b.c.d cannot be resolved to a type
 a.b.c.d.XXXXX cannot be resolved to a type
 The method isInWorkspace(Class<? extends EPackage>) in the type AbstractAcceleoGenerator is not applicable for the arguments (Class<XXXX>)

You need a dependency with the plugin "a.b.c.d" to use the element of the metamodel it contains. Have a look a the MANIFEST.MF file and in its "dependencies" tab, you should add the dependency to "a.b.c.d"

My generation fails with a 'package not found' exception









How can I run a generation in a standalone environment?

Q : Can I run an Acceleo generation outside of Eclipse?


How can I compile my mtl files in a standalone environment?




 public class AcceleoStandaloneCompiler extends AcceleoCompiler {
   public void execute() throws BuildException {
   public void registerResourceFactories() {
     // Uncomment the following if you need to use UML models
   public void registerPackages() {
     // Uncomment if you need to use UML models
     // EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
   public void registerLibraries() {
     CodeSource acceleoModel = MtlPackage.class.getProtectionDomain().getCodeSource();
     if (acceleoModel != null) {
       String libraryLocation = acceleoModel.getLocation().toString();
       if (libraryLocation.endsWith(".jar")) {
     } else {

Can Acceleo work with ClearCase?



 public IAcceleoGenerationStrategy getGenerationStrategy() {
   return new WorkspaceAwareStrategy();


How to migrate from Acceleo 2 to Acceleo 3?












How do I compare data to an enumeration value?



Feature 'startHeaderPosition' not found

  org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'startHeaderPosition' not found


How to use a Java service in Acceleo


Java service in Acceleo.

My query is only executed once






How can I use multiple metamodels in an Acceleo module ?

Multiple metamodels

How does the overriding system works in Acceleo ?


Static overriding


 module A
 public templateA
 protected templateB
 private templateC
 public templateD
 public queryA
 protected queryB
 private queryC
 module B extends A
 public templateD extends templateD

With static overriding, the module B has access to:

  • moduleA.templateA
  • moduleA.templateB
  • moduleA.templateD (by calling super in moduleB.templateD)
  • moduleA.queryA
  • moduleA.queryB



 --- Java ---
 class A
 methodA {}
 method B {methodA()}
 class B extends A
 methodA overrides methodA {}
 methodB overrides methodB {super.methodB}


  • B.methodB (our starting point)
  • A.methodB (the call to super)


Now let's consider those modules:

 --- Acceleo ---
 module A
 templateB [templateA/]
 module B extends A
 templateA overrides templateA
 templateB overrides templateB [super/]
 module C
 import module B


  • B.templateB (the entry point)
  • A.templateB (the call to super)


Dynamic overriding

Dynamic overriding is used thanks to the extension point "org.eclipse.acceleo.engine.dynamic.templates". It is not advisable to use it in order to create a generator, it should mainly be used in order to customize an existing generator. Let's consider that you have a great UML to Java generator but you have to customize the generator for a specific project (specific naming convention for example or maybe you want to generate a specific kind of Java for a J2EE framework). You have several options:


With the dynamic overriding, you can add new modules to an existing generator but those modules and the templates that they contain will be used in priority. For example, let's consider those modules:

 --- Acceleo ---
 module A
 module B
 imports moduleA
 -- The dynamic module in another plugin --
 module C extends moduleA

If you are calling in your existing generator the templateA from the the moduleB, the dynamic template C.templateA will be used instead. The existing generator does not know about the new generator and it has no dependencies with this other generator but since we have installed the new generator as a plugin in the same Eclipse instance as the existing generator and since the new generator uses the dynamic module extension point, all its templates that are overriding a template from the original generator will be used instead of the original templates. In that way, it is closer to aspect oriented programming. You need to have deployed your existing generator and the new generator in the same Eclipse instance in order to use this mechanism as it is using Eclipse extension points.

Nothing is generated

Try to use the XMI based serialization: right click on your project -> properties -> acceleo -> check XMI Binary serialization produce smaller and faster ".emtl" files (Acceleo modules once compiled) but the XMI serialization produce "smarter" files that can handle resolve the URI of the element of the metamodel more easily.

How to programmatically profile a generator

It is possible to programmatically attach a profiler to a generator. For example in you UI plugin add the following code around the call to the generator :

 --- Java ---
 Profiler profiler = new Profiler();
 generator.doGenerate( ... )
 String profileURI = ... + ".mtlp"; // URI of the profiling results file

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Predicate

Add com.google.collect as a dependency of your generator. (MANIFEST.MF -> Dependencies tab -> Add -> com.google.collect)

I can't find my metamodel in the new project/module wizard

If you have a metamodel in the workspace, and if you want to use it in an Acceleo project, starting with Acceleo 3.2, you can find it in the runtime section of the metamodel selection dialog. You can see an example in the following screenshot:


Is it possible to change the "start of user code" / "end of user code" generated for a protected area?


Is it possible to generate in several directories during one generation?

A regular Acceleo generator has only one output folder. It is possible to use a common ancestor of two folders (for example "A") and to use a longer path for the file to generate (for example "B/C/D/E" and "B/F/G/H") to create a generation in to different folders (here "A/B/C/D/E" and "A/B/F/G/H").

Can we copy files along the generation?

Acceleo can only generate text, it does not copy files.

How can I access UML stereotype values from Acceleo?

You can use a query such as this one :

 [query public getTaggedValue(stereotypedElement : Element, stereotypeName : String, propertyName : String) : OclAny = 
   let stereotype : Stereotype = stereotypedElement.getAppliedStereotype(stereotypeName) in
     if not stereotype.oclIsUndefined() then
       stereotypedElement.getValue(stereotype, propertyName)

How can I use Xcore with Acceleo?

If you want to use a Xcore based meta-model with Acceleo, you need to define a non-relative URI for your package.

 package org.eclipse.xcore.test
 class MyClass {
 	String name

The URI of the package defined above would not work since it is considered by EMF as a relative one (org.eclipse.xcore.test). In order to fix this issue, please use a non relative URI for your Xcore meta-model like this:

 @Ecore(nsURI="http://www.eclipse.org/xcore/test", nsPrefix="xcoretestprefix")
 package org.eclipse.xcore.test
 class MyClass {
 	String name

Please be careful with the case of the properties (nsURI and nsPrefix) since the 1.0 version of Xcore does not validate those properties. Once the code of your meta-model is generated, you can deploy your meta-model in your Eclipse where Acceleo is installed and start working with it.

How can I use UML profiles with my generator?

In the "registerPackages(...)" method of your Java launcher, you need to "register" the location of the profiles with the following piece of code:

 Map uriMap = resourceSet.getURIConverter().getURIMap();  
 URI uri = URI.createURI("platform:/plugin/org.eclipse.uml2.uml.resources/");
 // For RTSJ (real time Java)
 uri = URI.createURI("platform:/plugin/org.topcased.uml2rtsj.thirdparty/");
 uriMap.put(URI.createURI("pathmap://RTSJ_PROFILE/rtsj.uml"), uri.appendSegment("profile").appendSegment(""));

Acceleo Portal