简体   繁体   English

Linux可执行文件使用javafx-maven-plugin失败

[英]Linux executable fails using javafx-maven-plugin

I have a multimodule maven project with JavaFX up and running. 我有一个运行JavaFX的多模块Maven项目。 I can create an jar file containing all classes that is executable through a maven assembly, so I know the packaged bundle works. 我可以创建一个jar文件,其中包含可通过maven程序集执行的所有类,因此我知道打包的捆绑包有效。 For conveniance I want to create a native bundle/executable using the javafx-maven-plugin 为了方便起见,我想使用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. 在Windows上可以正常运行,创建一个可以运行的exe文件。 However executing the same thing on Linux, Maven runs through but the executable fails to start properly with these two messages: 但是,在Linux上执行相同的操作时,Maven可以运行,但是可执行文件无法正确启动,并显示以下两条消息:

OpenPatricianDisplay-0.5.0-SNAPSHOT No main class specified OpenPatricianDisplay-0.5.0-SNAPSHOT未指定主类
OpenPatricianDisplay-0.5.0-SNAPSHOT Failed to launch JVM OpenPatricianDisplay-0.5.0-SNAPSHOT无法启动JVM

Taking a look at the cfg files of the Windows and Linux bundle shows that they are different. 查看Windows和Linux捆绑软件的cfg文件,可以发现它们是不同的。 When replacing the Linux one with the one from Windows a different errors is created. 当用Windows中的Linux替换Linux中的一个时,会产生不同的错误。 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. 在Linux上使用该插件创建单个模块JavaFX演示应用程序即可。 To figure out if it is the Maven plugin or the underlying packager, I tried the following the Ant examples . 为了弄清楚它是Maven插件还是底层打包程序,我尝试了以下Ant示例 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: Hello World示例运行良好(第10.4.1章),但是当尝试使用外部jar文件(第10.4.3章)时,即使构建失败:

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. /home/andi/eclipse/intellij/jdk1.8.0_60/demo/javafx_samples/src/Ensemble8/build.xml:34:必须指定至少一个要打包的文件集。

The build.xml 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. 因此,看起来这些示例不是Java 1.8.0_60的最新版本。 The only difference to the build.xml from the example is the path to the JAVA_HOME. 该示例与build.xml的唯一区别是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. 是否有人对以下问题有任何想法:a)如何使用ant build处理问题以证明/证明打包程序是问题,或b)甚至更好地了解运行maven插件时可能出现的问题。

Environment: Linux Mint 17.2 KDE 环境:Linux Mint 17.2 KDE

  • JDK 1.8.0_60 JDK 1.8.0_60
  • Ant 1.9.3 蚂蚁1.9.3
  • Maven 3.0.5 Maven的3.0.5
  • javafx-maven-plugin 8.1.4 javafx-maven-plugin 8.1.4

This is at least a partial answer to the issue with the build for ant. 这至少是对ant构建问题的部分答案。 As it turns out the documentation is outdated, but I figured it out when taking a look at the Ant task definition . 事实证明, 文档已经过时了,但是当我看一下Ant任务定义时,我就知道了。

The <fx:jar> elements requires some more children for it to work: <fx: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: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> . 特别是<manifest><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. 编辑: javafx-maven-plugin的原始问题原来是打包程序本身和配置文件查找中的问题。 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.- 在JDK中解决此问题之前,更新至版本8.1.5并在<configuration>添加<bundler>linux.app</bundler> <configuration>是一种解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM