本文介绍了Linux可执行文件使用javafx-maven-plugin失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启动并运行JavaFX的多模块maven项目。我可以创建一个包含所有可通过maven程序集执行的类的jar文件,因此我知道打包的包工作。
为了方便我想使用

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>

这在Windows上工作正常,创建一个可以运行的exe文件。无论在Linux上执行相同的操作,Maven都会运行,但可执行文件无法正确启动这两条消息:

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:

查看Windows和Linux捆绑包的cfg文件显示它们是不同的。使用Windows中的Linux替换Linux时,会创建不同的错误。所以我不认为它们不同的事实是原因。
使用Linux上的插件创建单个模块JavaFX演示应用程序。为了弄清楚它是Maven插件还是底层打包器,我尝试了以下。 Hello World示例工作正常(第10.4.1节)但是当尝试使用外部jar文件(第10.4.3节)时,即使构建失败:

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.xml

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>

因此看起来这些示例与Java 1.8.0_60不是最新的。与示例中build.xml的唯一区别是JAVA_HOME的路径。

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.

有没有人知道:
a)如何处理问题使用ant构建来证明/反驳打包器是问题或
b)甚至可以更好地了解运行maven插件时可能出现的问题。

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 orb) even better have some insights into what might be the problem when running the maven plugin.

环境:
Linux Mint 17.2 KDE

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

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

推荐答案

这至少是针对ant构建问题的部分答案。事实证明,已过时,但是当我看一下时我想出来了。

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.

< fx:jar> 元素需要更多孩子才能工作:

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>

特别是< manifest> < FX:文件集> 。有了这个,我就可以将演示应用程序创建为可执行的本机包。

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

编辑: <$ c $的原始问题c> javafx-maven-plugin 原来是打包器本身的问题以及配置文件的查找。更新到版本 8.1.5 并在<$ c中添加< bundler> linux.app< / bundler> $ c>< configuration> 是一种解决方法,直到在JDK中固定.-

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.-

这篇关于Linux可执行文件使用javafx-maven-plugin失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 12:22