我有疑问。如何使用Ant为JavaFX应用程序制作胖jar?我知道在互联网上有一些问题,但它涉及Java应用程序,而不是JavaFX应用程序。我认为这是不同的,因为我试图遵循这个教程,它适用于Java应用程序,但在尝试运行应用程序后使用fxml文件的JavaFX应用程序中,它返回NullPointerException:location是必需的(是的,我尝试了修改程序路径到fxml文件,并使用ClassLoader,它没有帮助)。我也尝试使用Ant的One Jar插件,效果相同。
我有以下build.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name="App" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="commons-cli-1.2.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpcore-ab-4.4.4.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpclient-cache-4.5.1.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpcore-4.4.4.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="jsoup-1.8.3.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpcore-nio-4.4.4.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpcore-4.4.3.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpmime-4.5.1.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="commons-codec-1.9.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="httpclient-4.5.1.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="commons-logging-1.2.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="C:\Users\User\OneDrive\Libraries">
<filename name="fluent-hc-4.5.1.jar"/>
</fileset>
</copy>
<mkdir dir="project" />
<copy todir="project">
<fileset dir="C:\Users\User\OneDrive\Code\java\workspace\App">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
<include name="httpclient-cache-4.5.1.jar"/>
<include name="httpcore-ab-4.4.4.jar"/>
<include name="jsoup-1.8.3.jar"/>
<include name="commons-cli-1.2.jar"/>
<include name="commons-codec-1.9.jar"/>
<include name="httpcore-4.4.3.jar"/>
<include name="fluent-hc-4.5.1.jar"/>
<include name="httpcore-nio-4.4.4.jar"/>
<include name="httpcore-4.4.4.jar"/>
<include name="commons-logging-1.2.jar"/>
<include name="httpclient-4.5.1.jar"/>
<include name="httpmime-4.5.1.jar"/>
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="Cp1250">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="App.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
</fx:resources>
<fx:application id="fxApplication"
name="Youtufy"
mainClass="pl.javastart.App.main.Main"
toolkit="fx"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/App.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="Javastart"/>
<attribute name="Implementation-Title" value="App"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="Youtufy" nativeBundles="none"
updatemode="background" >
<fx:platform basedir="${java.home}"/>
<fx:info title="App" vendor="Javastart"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
</target>
如何修改它,制作包含所有依赖项的胖jar?我知道在Maven中更容易制作,但我想知道,这在Ant中是否可行。 此致