Java Ant:无法创建任务或类型fx:deploy
我试图使用Ant将Java应用程序打包为一个自包含的应用程序。但是,当我尝试使用Java Ant:无法创建任务或类型fx:deploy,java,ant,Java,Ant,我试图使用Ant将Java应用程序打包为一个自包含的应用程序。但是,当我尝试使用taskdef从antjavafx.jar加载javafxant任务时,会出现“创建任务或类型失败”错误。我的dist目标如下(执行jar目标及其所有依赖项时不会出错): 根据要求提供完整示例: C:\Users\John\eclipse workspace\HelloWorld\src\HelloWorld\HelloWorld.java包含: package helloworld; public class H
taskdef
从antjavafx.jar
加载javafxant任务时,会出现“创建任务或类型失败”错误。我的dist
目标如下(执行jar
目标及其所有依赖项时不会出错):
根据要求提供完整示例:
C:\Users\John\eclipse workspace\HelloWorld\src\HelloWorld\HelloWorld.java包含:
package helloworld;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
<?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>
C:\Users\John\eclipse workspace\HelloWorld\src\HelloWorld\build.xml包含:
package helloworld;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
<?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>
我的第一个问题:Q:jdk_home/lib中是否有
antjavafx.jar
?答案似乎是“是”
问:在
根元素中是否有xmlns:fx=“javafx:com.sun.javafx.tools.ant”
问:第45行具体是什么
另外:请务必阅读Oracle文档:
增编:
请查看此处的建议(您的确切错误和几种可能的解决方法):
更新:
根据您的更新,听起来您想为Ant构建设置JRE:
Eclipse>您的项目>build.xml>外部工具配置>JRE选项卡>
我的第一个问题:Q:jdk_home/lib中是否有antjavafx.jar
?答案似乎是“是”
问:在
根元素中是否有xmlns:fx=“javafx:com.sun.javafx.tools.ant”
问:第45行具体是什么
另外:请务必阅读Oracle文档:
增编:
请查看此处的建议(您的确切错误和几种可能的解决方法):
更新:
根据您的更新,听起来您想为Ant构建设置JRE:
Eclipse>您的项目>build.xml>外部工具配置>JRE选项卡>
是的,xmlns:fx=“javafx:com.sum.javafx.tools.ant”
在我的
元素中。作为ant的替代方案,您可能希望尝试或。我不经常使用ant,所以我不能提供太多关于如何让你的应用程序与ant一起工作的建议,除了非常仔细地将你的ant文件与Oracle提供的示例项目的ant文件进行比较,如果你仍然无法解决问题,发布到StackOverflow而不是部分文件片段。请根据下面的“我的更新”尝试Eclipse>YOUR PROJECT>build.xml>External tools configuration>JRE Tab>
。@jewelsea您还需要我添加什么才能使其成为MCVE?build.xml文件中的其他任务不会导致此错误,我试图构建的任何源代码也不会导致此错误。你需要一些人可以复制、粘贴和执行的东西来复制问题,而不需要任何添加或更改。如果源代码不是问题(并不是因为这是一个构建问题),那么只需为hello world应用程序提供源代码即可。您需要提供正在使用的完整ant文件。如果某些任务与错误无关,则删除它们,但ant文件仍应是完整的,以便复制和粘贴允许复制,否则猜测可能的错误只是猜测。是的,xmlns:fx=“javafx:com.sum.javafx.tools.ant”
在我的
元素中。作为ant的替代,您可能希望尝试或。我不经常使用ant,所以我不能提供太多关于如何让你的应用程序与ant一起工作的建议,除了非常仔细地将你的ant文件与Oracle提供的示例项目的ant文件进行比较,如果你仍然无法解决问题,发布到StackOverflow而不是部分文件片段。请根据下面的“我的更新”尝试Eclipse>YOUR PROJECT>build.xml>External tools configuration>JRE Tab>
。@jewelsea您还需要我添加什么才能使其成为MCVE?build.xml文件中的其他任务不会导致此错误,我试图构建的任何源代码也不会导致此错误。你需要一些人可以复制、粘贴和执行的东西来复制问题,而不需要任何添加或更改。如果源代码不是问题(并不是因为这是一个构建问题),那么只需为hello world应用程序提供源代码即可。您需要提供正在使用的完整ant文件。如果某些任务与错误无关,则删除它们,但ant文件仍应是完整的,以便复制和粘贴允许复制,否则猜测可能有什么错误只是猜测。第45行(错误在45,而不是49)是
元素。那么,您完成了这项工作吗?听起来很像是在使用Eclipse。我希望您能够使用Eclipse“Externl工具配置”菜单来指向正确的JRE、jfxrt.jar和ant-javafx.jar。您不必担心任何环境变量。请随时通知我们!不,我还没有让它工作。我不得不使用env.JAVA\u HOME
的原因是JAVA.HOME
将我指向JRE的基本目录,即使我使用外部工具配置指向JDKantjavafx.jar
位于JDK目录中,而不是JRE目录中。这可能与路径包含正斜杠和反斜杠的混合有关吗?我没主意了。第45行(错误在45,而不是49)是
元素。那么,您是否可以使用它?听起来很像是在使用Eclipse。我希望您能够使用Eclipse“Externl工具配置”菜单来指向正确的JRE、jfxrt.jar和ant-javafx.jar。您不必担心任何环境变量。请随时通知我们!不,我还没有让它工作。我不得不使用env.JAVA\u HOME
的原因是JAVA.HOME
将我指向基本目录
<?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>
Buildfile: C:\Users\John\eclipse-workspace\HelloWorld\src\helloworld\build.xml
[echo] C:\Program Files\Java\jdk1.8.0_151/lib/ant-javafx.jar
init:
[mkdir] Created dir: C:\Users\John\eclipse-workspace\HelloWorld\antbuild
compile:
[javac] Compiling 1 source file to C:\Users\John\eclipse-workspace\HelloWorld\antbuild
jar:
[jar] Building jar: C:\Users\John\eclipse-workspace\HelloWorld\dist\HelloWorld-20171121.jar
dist:
BUILD FAILED
C:\Users\John\eclipse-workspace\HelloWorld\src\helloworld\build.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