0

I have a multimodule maven project with JavaFX up and running. I can create an jar file containing all classes that is executable through a maven assembly, so I know the packaged bundle works. For conveniance I want to create a native bundle/executable using the javafx-maven-plugin

<profile>
    <id>build-installer</id>
    <properties>
    <native.output.dir>${project.build.directory}/jfx/native/${project.build.finalName}</native.output.dir>
    <native.output.dir.app>${native.output.dir}/app</native.output.dir.app>
    <native.output.dir.security>${native.output.dir}/runtime/jre/lib/security</native.output.dir.security>
    <native.app.jar>${native.output.dir.app}/${project.build.finalName}-jfx.jar</native.app.jar>
    </properties>
    <dependencies>
    <dependency>
        <groupId>ch.sahits.game</groupId>
        <artifactId>OpenPatricianDisplay</artifactId>
        <version>${project.version}</version>
    </dependency>
    </dependencies>
    <build>

    <plugins>

        <plugin>
        <groupId>com.zenjava</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>8.1.2</version>
        <configuration>
            <mainClass>ch.sahits.game.OpenPatrician</mainClass>
            <verbose>true</verbose>
        </configuration>
        <executions>
            <execution>
            <phase>package</phase>
            <goals>
                <goal>native</goal>
            </goals>
            </execution>
        </executions>
        </plugin>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
            <id>create zip archive</id>
            <phase>install</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>

                <echo>Creating self-contained zip</echo>
                <zip destfile="${project.build.directory}/OpenPatrician-${project.version}.zip" basedir="${native.output.dir}" />

                </target>
            </configuration>
            </execution>
        </executions>
        </plugin>

    </plugins>
    </build>

</profile>

This works fine on Windows, creates an exe file that can be run. However executing the same thing on Linux, Maven runs through but the executable fails to start properly with these two messages:

OpenPatricianDisplay-0.5.0-SNAPSHOT No main class specified
OpenPatricianDisplay-0.5.0-SNAPSHOT Failed to launch JVM

Taking a look at the cfg files of the Windows and Linux bundle shows that they are different. When replacing the Linux one with the one from Windows a different errors is created. So I do not think the fact that they are different is the cause. Creating a single module JavaFX demo app with the plugin on Linux works. To figure out if it is the Maven plugin or the underlying packager, I tried the following the Ant examples. The Hello World example works fine (chapter 10.4.1) however when trying the example with external jar files (chapter 10.4.3) even the build fails:

BUILD FAILED
/home/andi/eclipse/intellij/jdk1.8.0_60/demo/javafx_samples/src/Ensemble8/build.xml:34: You must specify at least one fileset to be packed.

The build.xml

<?xml version="1.0" encoding="UTF-8" ?>

<project name="Ensemble8 JavaFX Demo Application" default="default" basedir="."
  xmlns:fx="javafx:com.sun.javafx.tools.ant">

  <property name="JAVA_HOME" value="/usr/lib/jvm/java-8-oracle"/>

  <path id="CLASSPATH">
    <pathelement location="lib/lucene-core-3.2.0.jar"/>
    <pathelement location="lib/lucene-grouping-3.2.0.jar"/>
    <pathelement path="classes"/>
  </path>

  <property name="build.src.dir" value="src"/>
  <property name="build.classes.dir" value="classes"/>
  <property name="build.dist.dir" value="dist"/>

  <target name="default" depends="clean,compile">

    <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
      uri="javafx:com.sun.javafx.tools.ant"
      classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>

      <fx:application id="ensemble8"
        name="Ensemble8"
        mainClass="ensemble.EnsembleApp"/>

      <fx:resources id="appRes">
    <fx:fileset dir="${build.dist.dir}" includes="ensemble8.jar"/>
        <fx:fileset dir="lib"/>
        <fx:fileset dir="${build.classes.dir}"/>
      </fx:resources>

      <fx:jar destfile="${build.dist.dir}/ensemble8.jar">
        <fx:application refid="ensemble8"/>
        <fx:resources refid="appRes"/>
      </fx:jar>

      <fx:deploy outdir="." embedJNLP="true"
        outfile="ensemble8"
        nativeBundles="all">

        <fx:application refId="ensemble8"/>

        <fx:resources refid="appRes"/>

        <fx:info title="Ensemble8 JavaFX Demo Application"
          vendor="Oracle Corporation"/>

      </fx:deploy>

  </target>

  <target name="clean">
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.dist.dir}"/>

    <delete>
      <fileset dir="${build.classes.dir}" includes="**/*"/>
      <fileset dir="${build.dist.dir}" includes="**/*"/>
    </delete>

  </target>

  <target name="compile" depends="clean">

    <javac includeantruntime="false"
      srcdir="${build.src.dir}"
      destdir="${build.classes.dir}"
      fork="yes"
      executable="${JAVA_HOME}/bin/javac"
      source="1.8"
      debug="on"
      classpathref="CLASSPATH">
    </javac>

    <!-- Copy resources to build.classes.dir -->

      <copy todir="${build.classes.dir}">
        <fileset dir="src/app/resources"/>
        <fileset dir="src/generated/resources"/>
        <fileset dir="src/samples/resources"/>
      </copy>

  </target>

</project>

So it looks the examples are not up to date with Java 1.8.0_60. The only difference to the build.xml from the example is the path to the JAVA_HOME.

Does anyone have an idea on: a) how to approach the issue with the ant build to prove/disprove that the packager is the problem or b) even better have some insights into what might be the problem when running the maven plugin.

Environment: Linux Mint 17.2 KDE

  • JDK 1.8.0_60
  • Ant 1.9.3
  • Maven 3.0.5
  • javafx-maven-plugin 8.1.4
hotzst
  • 7,238
  • 9
  • 41
  • 64
  • Why are you using the `maven-antrun-plugin`? The whole point of using `javafx-maven-plugin` is to avoid using ant or have any dependency on the ant files. I have a [small project](https://github.com/TheItachiUchiha/MediaPlayerFX/blob/master/pom.xml), for which I have created packages without any issue on Windows, Ubuntu and Mac using maven plugin. – ItachiUchiha Sep 26 '15 at 09:15
  • You do not need to pass `` configuration to the plugin as well, unless you want it to be a part of maven lifecycle. Since, native builds takes some time, a better and more cleaner way to do it would be to fire `mvn jfx:native` from the command line whenever required. – ItachiUchiha Sep 26 '15 at 10:38
  • I do intend to use javafx-maven-plugin, however as it is currently not working on Linux, I tried the approach with ant (not bothering with maven at all) to see if it is an issue with the packager or the maven plugin. – hotzst Sep 26 '15 at 12:05
  • Can you add the environment details? – ItachiUchiha Sep 26 '15 at 12:08
  • I just cross checked the plugin on Linux Mint 17.2, everything works perfectly. The debian package is created and it works when you double click on it. You may want to clone my project and run a `mvn jfx:native` on it on your machine. – ItachiUchiha Sep 26 '15 at 19:18
  • I would have that cloning your project (MediaPlayerFX) and creating a build would create a runnable executable, as it does not have any modules, however it fails with the same error. Thinking about the JDK: I get it though this repository: deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main, I will check if this can be reproduced when using the JDK downloaded from oracle. – hotzst Sep 27 '15 at 08:17
  • Using the JDK from Oracle produces the same error. – hotzst Sep 27 '15 at 09:04
  • The only workaround I can think of is to run your build in some other linux environment. Is your project open-sourced? – ItachiUchiha Sep 27 '15 at 09:48
  • Yes it is: https://sourceforge.net/projects/openpatrician/ with SVN checkout URL svn checkout http://svn.code.sf.net/p/openpatrician/code/trunk/OpenPatrician. However trying on a different machine (running CentOS 5), was one of the first things I tried. – hotzst Sep 27 '15 at 10:13

1 Answers1

1

This is at least a partial answer to the issue with the build for ant. As it turns out the documentation is outdated, but I figured it out when taking a look at the Ant task definition.

The <fx:jar> elements requires some more children for it to work:

  <fx:application id="ensemble8"
    name="Ensemble8"
    mainClass="ensemble.EnsembleApp"/>

  <fx:resources id="appRes">
    <fx:fileset dir="${build.dist.dir}" includes="ensemble8.jar"/>
    <fx:fileset dir="lib"/>
    <fx:fileset dir="${build.classes.dir}"/>
  </fx:resources>

  <fx:jar destfile="${build.dist.dir}/ensemble8.jar">
    <fx:application refid="ensemble8"/>
    <fx:resources refid="appRes"/>
    <fx:fileset dir="${build.classes.dir}"/>
 <!-- Customize jar manifest (optional) -->
<manifest>
    <attribute name="Implementation-Vendor" value="Samples Team"/>
    <attribute name="Implementation-Version" value="1.0"/>
<attribute name="Main-Class" value="ensemble.EnsembleApp" />
</manifest>
</fx:jar>

Especially the <manifest> and the <fx:fileset>. With that in place I can create the demo application as native bundle that is executable.

EDIT: The original issue with the javafx-maven-plugin turns out to be a problem in the packager itself and the lookup of the configuration file. Updating to version 8.1.5 and adding <bundler>linux.app</bundler> in the <configuration> is a workaround until the issue is fixed in the JDK.-

hotzst
  • 7,238
  • 9
  • 41
  • 64
  • Just for other readers, finding this SO-question: the issue/bug within oracle packager starts from Java 1.8.0 update 40 and is still not fixed (today: 22th November 2015). Another problem comes from Java 1.8.0 update 60, it is possible to set custom JRE-runtime, but there exists a [bug when writing the CFG-file](https://github.com/javafx-maven-plugin/javafx-maven-plugin/issues/167) – FibreFoX Nov 22 '15 at 17:30