ANT:无法创建任务或类型FX:部署



我正在尝试使用ant将我的Java应用程序作为独立应用程序包装。但是,当我尝试使用taskdefant-javafx.jar加载JAVAFX ANT任务时,我会获得"无法创建任务或键入错误"错误。我的dist目标如下(jar目标及其所有依赖项都没有错误执行):

<target name="dist" depends="jar">
    <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                                 uri="javafx:com.sun.javafx.tools.ant"
                                 classpath="${env.JAVA_HOME}/lib/ant-javafx.jar"/>
    <fx:deploy outdir="${antbuild}/packager" outfile="InventoryManager" nativeBundles="exe">
        <fx:application name="Inventory Manager" mainClass="inventorymanager.RunInventoryManager" version="1.0"/>
        <fx:resources>
            <fx:fileset dir="${dist}" includes="InventoryManager-${DSTAMP}.jar"/>
        </fx:resources>
        <fx:info title="Inventory Manager" description="Inventory manager for a store.">
            <fx:association extension="inv" description="Inventory File"/>
        </fx:info>
        <fx:bundleArgument arg="win.menuGroup" value="Inventory Manager"/>
    </fx:deploy>
</target>

当我运行此目标时,我会收到以下错误:

BUILD FAILED
C:UsersJohneclipse-workspaceInventoryManagersrcinventorymanagerbuild.xml:45: Problem: failed to create task or type javafx:com.sum.javafx.tools.ant:deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

<echo>${env.JAVA_HOME}/lib/ant-javafx.jar</echo> out C:Program FilesJavajdk1.8.0_151/lib/ant-javafx.jar,所以我知道 JAVA_HOME指向正确的位置。

该路径包含前向和反斜线的混合的事实会引起问题吗?如果没有,我还能尝试什么?

如果这与问题有关,我正在从Windows 10上的Eclipse氧气调用蚂蚁。

更新:我尝试使用此处找到的解决方案。这是不成功的,因此我尝试将${env.JAVA_HOME}更改为${java.home},以便他们俩都指向同一位置<echo>${java.home}/lib/ant-javafx.jar</echo> usf C:Program FilesJavajdk1.8.0_151jre/lib/ant-javafx.jar,这不是通往JAR文件的正确路径。有没有办法进入C:Program FilesJavajdk1.8.0_151而不诉诸使用环境变量?

现在,我已经弄清楚了如何打开冗长的话,dist任务的详细输出如下:

parsing buildfile jar:file:/C:/Program%20Files/Java/jdk1.8.0_151/lib/ant-javafx.jar!/com/sun/javafx/tools/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/Java/jdk1.8.0_151/lib/ant-javafx.jar!/com/sun/javafx/tools/ant/antlib.xml from a zip file
 [macrodef] creating macro  javafx:com.sun.javafx.tools.ant:init-ant

按要求的完整示例:

c: users john eclipse-workspace helloworld src src helloworld helloworld.java包含:

package helloworld;
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

c: users john eclipse-workspace helloworld src src helloworld build.xml包含:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Hello World" default="dist" basedir="C:/Users/John/eclipse-workspace/HelloWorld" xmlns:fx="javafx:com.sum.javafx.tools.ant">
    <description>
            Ant build of a self-contained Hello World application.
    </description>
    <!-- Set directory properties for this build -->
    <property name="antbuild" location="antbuild"/>
    <property name="src" location="src"/>
    <property name="dist" location="dist"/>
    <property environment="env"/>
    <target name="init">
        <tstamp/>
        <mkdir dir="${antbuild}"/>
    </target>
    <target name="compile" depends="init" description="Compiles the source code.">
        <javac includeantruntime="false" srcdir="${src}" destdir="${antbuild}"/>
    </target>
    <target name="jar" depends="compile" description="Creates the JAR file for the application.">
        <manifest file="${antbuild}/MANIFEST.MF">
            <attribute name="Main-Class" value="helloworld.HelloWorld"/>
        </manifest>
        <jar manifest="${antbuild}/MANIFEST.MF" jarfile="${dist}/HelloWorld-${DSTAMP}.jar" basedir="${antbuild}"/>
    </target>
    <echo>${env.JAVA_HOME}/lib/ant-javafx.jar</echo>
    <target name="dist" depends="jar">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${env.JAVA_HOME}/lib/ant-javafx.jar;src"/>
        <fx:deploy outdir="${antbuild}/packager" outfile="HelloWorld" nativeBundles="exe">
            <fx:application name="Hello World" mainClass="helloworld.HelloWorld" version="1.0"/>
            <fx:resources>
                <fx:fileset dir="${dist}" includes="HelloWorld-${DSTAMP}.jar"/>
            </fx:resources>
            <fx:info title="Hello World" description="Hello World program."/>
            <fx:bundleArgument arg="win.menuGroup" value="Hello World"/>
        </fx:deploy>
    </target>
    <target name="cleanup">
        <!-- Deletes the antbuild directory -->
        <delete dir="${antbuild}"/>
        <delete dir="${dist}"/>
    </target>
</project>

试图运行distbuild.xml目标产生以下(非verbose)输出:

Buildfile: C:UsersJohneclipse-workspaceHelloWorldsrchelloworldbuild.xml
        [echo] C:Program FilesJavajdk1.8.0_151/lib/ant-javafx.jar
init:
       [mkdir] Created dir: C:UsersJohneclipse-workspaceHelloWorldantbuild
compile:
       [javac] Compiling 1 source file to C:UsersJohneclipse-workspaceHelloWorldantbuild
jar:
         [jar] Building jar: C:UsersJohneclipse-workspaceHelloWorlddistHelloWorld-20171121.jar
dist:
BUILD FAILED
C:UsersJohneclipse-workspaceHelloWorldsrchelloworldbuild.xml:36: 
Problem: failed to create task or type javafx:com.sum.javafx.tools.ant:deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

Total time: 1 second

我的第一个问题:问: jdk_home/lib中的 ant-javafx.jar吗?答案似乎是"是"。

问:您的<project>根元素中有xmlns:fx="javafx:com.sun.javafx.tools.ant"吗?

问:Line 45到底是什么?

另外:请务必阅读Oracle文档:

https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/javafx_ant_tasks.html

附录:

请在此处查看建议(您的确切错误以及几个可能的解决方法):Javafx构建失败

更新:根据您的更新,听起来您想为蚂蚁构建设置JRE:

eclipse>您的项目> build.xml>外部工具配置> JRE选项卡> &lt; =选择您想要的JRE

重要的是要注意,Windows变量" Java_home"是不是Eclipse或Ant。

也必须注意,您用于蚂蚁构建的JRE可能与您用于项目的JRE不同。

最新更新