Build Runnable JAR of Xtend + JavaFX project in Maven

After a long research I’ve found a site that helps with compiling Xtend using Maven – http://www.eclipse.org/xtend/download.html – pretty straightforward, isn’t it? However, it lacks a few more things.

My goal was to compile and package Java 8 project together with JavaFX, written mostly in Xtend (in place of Java) with unpacked libraries into one Runnable JAR. In the end I’d like it to be compatible with e(fx)clipse IDE. Here’s how.

Create pom.xml

Make sure you have Maven installed in your system. Then call this:

This will ask you about groupId, artifactId, version and package. Based on that information it creates a pom.xml file that is configured to compile Xtend project into Java 1.5.

Improve pom.xml

What’s left:

  1. I expect it to work with Java 8, not only Java 5
  2. add resources: *.fxml  and *.css  files
  3. add dependencies (other libs, like minimal-json)
  4. package jar by unpacking depedencies into that jar

And this jar needs to be runnable!

1. Java version

To correct Java 1.5 to newer version of source/target find similiar fragment and simply edit 1.5 to e.g. 1.8:

2. Resources

Pattern is very simple. Just put this snippet into <build>  part.

3. Dependencies

<dependencies>  part is already in generated file. Add in there what you need. My choice at the time was to add minimal-json and JNativeHook.

4. Package

Very important step is to package my app into single .jar file. Amongs many options I choosed to use maven-assembly-plugin:

One of interesting parts is: <appendAssemblyId>false</appendAssemblyId>  because filename of the output file results in  theconsole-0.1-SNAPSHOT.jar  instead of   theconsole-0.1-SNAPSHOT-jar-with-dependencies.jar .

Another important part is <mainClass>  tag – it defines which class should be the entry point for the app. That’s how we configure the Runnable JAR.

Summary

Now I can simply run mvn package  to get my so awaited .jar inside of target  folder. To see whole configuration in one snippet take a look at the pom.xml in The Console project.