Hello Acceleo community,
I have posted this topic another forum but I have discovered this one now and I find it more apropriate.
When trying to generate java code from an uml model with the acceleo maven plugin in standalone mode (without eclipse) I have the following error:
The generation failed to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates.
The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator. It could also come from a missing [comment @main/]
in the template used as the entry point of the generation.
I have downloaded the source of acceleo.
I have focused on the project/module : /org.eclipse.acceleo.maven.tests
I have just changed the following part in the pom to be sure the accelo plugin is called to compile the mlt files
<plugin>
<groupId>org.eclipse.acceleo</groupId>
<artifactId>org.eclipse.acceleo.maven</artifactId>
<version>3.5.0-SNAPSHOT</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>acceleo-compile</goal> XXXHEREXXXX
</goals>
</execution>
</executions>
<configuration> <useBinaryResources>false</useBinaryResources> <usePlatformResourcePath>true</usePlatformResourcePath>
<acceleoProject> <root>${project.basedir}</root> <entries> <entry> <input>src/main/java</input>
<output>target/classes</output> </entry> </entries> </acceleoProject> <packagesToRegister>
<packageToRegister>org.eclipse.uml2.uml.UMLPackage</packageToRegister> </packagesToRegister>
</configuration>
</plugin>
The emlt files are well generated
Then I have create a second maven project with an uml model in it, the one of acceleo example.uml
I have called the plugin generated with the previous module
<plugin>
<groupId>org.eclipse.acceleo</groupId>
<artifactId>org.eclipse.acceleo.maven.launcher</artifactId>
<version>3.5.0-SNAPSHOT</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>acceleo-launcher</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- generatorClass>org.eclipse.acceleo.module.sample.main.Generate</generatorClass -->
<generatorClass>org.eclipse.acceleo.module.example.uml2java.helios.GenerateJava</generatorClass>
<model>${basedir}\src\main\model\example.uml</model>
<outputFolder>${basedir}\src</outputFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.acceleo</groupId>
<artifactId>org.eclipse.acceleo.maven.tests</artifactId>
<version>3.6.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
But I am getting everytime the error
[INFO] Generation completed.
The generation failed to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates.
The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator. It could also come from a missing [comment @main/]
in the template used as the entry point of the generation.
[INFO]
I have checked that /org.eclipse.acceleo.maven.tests/src/main/java/org/eclipse/acceleo/module/example/uml2java/helios/generateJava.mtl
contains
[template public generateClass(c : Class)]
[comment @main /]
and that /org.eclipse.acceleo.maven.tests/src/main/java/org/eclipse/acceleo/module/example/uml2java/helios/GenerateJava.java
contains
@Override
public void registerPackages(ResourceSet resourceSet) {
System.out.println("kjkj");
super.registerPackages(resourceSet);
if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
System.out.println("kjkjaa");
resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
}
/*
* TODO If you need additional package registrations, you can register them here. The following line
* (in comment) is an example of the package registration for UML. If you want to change the content
* of this method, do NOT forget to change the "@generated" tag in the Javadoc of this method to
* "@generated NOT". Without this new tag, any compilation of the Acceleo module with the main template
* that has caused the creation of this class will revert your modifications. You can use the method
* "isInWorkspace(Class c)" to check if the package that you are about to register is in the workspace.
* To register a package properly, please follow the following conventions:
*
* if (!isInWorkspace(UMLPackage.class)) {
* // The normal package registration if your metamodel is in a plugin.
* resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
* } else {
* // The package registration that will be used if the metamodel is not deployed in a plugin.
* // This should be used if your metamodel is in your workspace and if you are using binary resource serialization.
* resourceSet.getPackageRegistry().put("/myproject/myfolder/mysubfolder/MyUMLMetamodel.ecore", UMLPackage.eINSTANCE);
* }
*
* To learn more about Package Registration, have a look at the Acceleo Launcher documentation (Help -> Help Contents).
*/
}
no idea any more...
thanks for your help