我喜欢将我的javafx应用程序构建到jar中。我使用以下ant脚本,它主要是从fxbuild生成的。我可以构建jar,但程序立即崩溃。它找不到我的一个库(见下文)。有人知道,为什么不包括罐子?
<?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="/path/to/repository/App/lib">
<filename name="controlsfx-8.20.8.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="/path/to/repository/App/lib">
<filename name="org.eclipse.jgit-3.5.1.201410131835-r.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="/path/to/repository/App/lib">
<filename name="openjfx-dialogs-1.0.2.jar"/>
</fileset>
</copy>
<copy todir="externalLibs">
<fileset dir="/path/to/repository/App/lib">
<filename name="jsch-0.1.51.jar"/>
</fileset>
</copy>
<mkdir dir="project" />
<copy todir="project">
<fileset dir="/path/to/repository/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="org.eclipse.jgit-3.5.1.201410131835-r.jar"/>
<include name="controlsfx-8.20.8.jar"/>
<include name="openjfx-dialogs-1.0.2.jar"/>
<include name="jsch-0.1.51.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="UTF-8">
<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="App"
mainClass="com.company.app.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="Company"/>
<attribute name="Implementation-Title" value="App"/>
<attribute name="Implementation-Version" value="2.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<mkdir dir="deploy" />
<fx:deploy
embedJNLP="false"
extension="false"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="App" nativeBundles="all"
updatemode="background" >
<fx:info title="App" vendor="Company"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
</target>
Caused by: java.lang.ClassNotFoundException: org.eclipse.jgit.api.errors.GitAPIException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more