Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Genmodel code generation via Maven build(Genmode code generation via Maven build)
Genmodel code generation via Maven build [message #1862834] Sun, 31 December 2023 11:42 Go to next message
Max Kratz is currently offline Max KratzFriend
Messages: 2
Registered: December 2023
Junior Member
Hello,

I'm currently wrapping my head around building multiple pre-existing projects (partly EMF/metamodels) via Maven.

One of the problems I stumbled upon is the source code generation process of Genmodels. I found some (more or less related) projects on the internet but I could not get them to run successfully:
- https://github.com/enikao/xcore-xtend-maven/tree/master
- https://github.com/BlackBeltTechnology/emf-genmodel-generator/tree/develop

I've created a minimal working example with a small Ecore metamodel and a pom.xml config for Maven to learn the correct way of generating the source code. The project can be found on GitHub: https://github.com/maxkratz/maven-ecore-modeling-example
Therefore, I added an MWE2 file that can be run inside Eclipse and *successfully* generates the metamodel code to `src-gen`.

However, if I run the project via Maven, I get an Exception that some of the MWE2 classes cannot be loaded:
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< org.example.model:org.example.model >-----------------
[INFO] Building Example Model 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- build-helper-maven-plugin:3.5.0:add-source (add-source) @ org.example.model ---
[INFO] Source directory: /home/maxkratz/gits/maven-ecore-modeling-example/org.example.model/src-gen added.
[INFO] 
[INFO] --- exec-maven-plugin:3.1.1:java (mwe2Launcher) @ org.example.model ---
0    [org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main()] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - org/eclipse/emf/mwe2/language/Mwe2RuntimeModule
java.lang.NoClassDefFoundError: org/eclipse/emf/mwe2/language/Mwe2RuntimeModule
	at org.eclipse.emf.mwe2.language.Mwe2StandaloneSetupGenerated.createInjector(Mwe2StandaloneSetupGenerated.java:47)
	at org.eclipse.emf.mwe2.language.Mwe2StandaloneSetupGenerated.createInjectorAndDoEMFRegistration(Mwe2StandaloneSetupGenerated.java:41)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:75)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)
	at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0(ExecJavaMojo.java:283)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ClassNotFoundException: org.eclipse.emf.mwe2.language.Mwe2RuntimeModule
	at org.codehaus.mojo.exec.URLClassLoaderBuilder$ExecJavaClassLoader.loadClass(URLClassLoaderBuilder.java:163)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 6 more


As far as I can see, all necessary dependencies are present in the plugin's configuration in the pom.xml file.

This leads me to ask two questions:
- Does anyone have a small example of how to build the metamodel source code from a Genmodel via Maven?
- What did I miss in my pom.xml configuration to resolve the NoClassDefFoundError/ClassNotFoundException?

I appreciate the help.

Best regards,
Max
Re: Genmodel code generation via Maven build [message #1862838 is a reply to message #1862834] Mon, 01 January 2024 10:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
The GEF project has a working example. It's easy to set up the environment for it:

https://github.com/eclipse/gef/blob/master/CONTRIBUTING.md

There is an m2e launch configuration available to run the Maven/Tycho build locally.

Here is the part where it specifies to launch the *.mwe2:

https://github.com/eclipse/gef/blob/f2384c5632f68b0ca2dec4088ffa2118214a8909/org.eclipse.gef.dot/pom.xml#L120-L185


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Genmodel code generation via Maven build [message #1862841 is a reply to message #1862838] Mon, 01 January 2024 14:01 Go to previous messageGo to next message
Max Kratz is currently offline Max KratzFriend
Messages: 2
Registered: December 2023
Junior Member
Thank you for your fast reply.

I tried to build the GEF project by checking out the repository's code and using Maven to run the build headlessly. Unfortunately, I'm unable to build the GEF project with Maven.

Under `CONTRIBUTING.md`, the documentation states that Java 11 must be used. However, if I use a Java 11 installation, Maven complains about class files compiled with a higher version. After some unsuccessful tries, I had a look at the Jenkins configuration file and observed that Jenkins uses JDK17 instead of Java 11. I switched my test environment to JDK17 but now I get an error when I try to build the main project:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:4.0.4:compile (default-compile) on project org.eclipse.gef.common: useJDK = BREE configured, but no toolchain of type 'jdk' with id 'JavaSE-1.8' found. See https://maven.apache.org/guides/mini/guide-using-toolchains.html -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf org.eclipse.gef.plugins:org.eclipse.gef.common


However, I compared the provided pom.xml file you mentioned and I noticed that I had at least two dependencies missing:
[...]
          <dependency>
            <groupId>org.eclipse.xtext</groupId>
            <artifactId>org.eclipse.xtext.common.types</artifactId>
            <version>${xtext-version}</version>
          </dependency>
          <dependency>
            <groupId>org.eclipse.xtext</groupId>
            <artifactId>org.eclipse.xtext.xtext.generator</artifactId>
            <version>${xtext-version}</version>
          </dependency>
[...]


I added them to my small example repo (https://github.com/maxkratz/maven-ecore-modeling-example/commit/a79d1d5f59db821155fbda36b7e2b2d1dbdedc77) and now the Maven build process runs successfully.

Thank you very much!
Re: Genmodel code generation via Maven build [message #1862842 is a reply to message #1862841] Mon, 01 January 2024 15:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
FYI, for anyone else looking at this post in the future, I have this in my <home>/.m2/toolschains.xml
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
  <toolchain>
    <type>jdk</type>
    <provides>
      <id>JavaSE-1.8</id>
      <version>1.8</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>C:/Program Files/Java/jdk1.8.0_261</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <id>JavaSE-11</id>
      <version>11</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <jdkHome>C:/Program Files/Java/jdk-11.0.13+8</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <id>JavaSE-17</id>
      <version>17</version>
      <vendor>adoptium</vendor>
    </provides>
    <configuration>
	    <jdkHome>C:/Program Files/Java/jdk-17.0.5+8</jdkHome>
    </configuration>
  </toolchain>
</toolchains>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Changed behavior of Undo/Redo menu's entries?
Next Topic:Access Ecore class Attribute with multiplicity 0..1 (Optional parameter)
Goto Forum:
  


Current Time: Thu May 02 07:03:15 GMT 2024

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

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

Back to the top