I'm trying to compile and run a JavaFX project using ant. Compilation using ant is OK, however, when I try to use ant run
and launch the application, i get this error:
run:
[java] Exception in Application start method
[java] java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
[java] at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
[java] Caused by: java.lang.RuntimeException: Exception in Application start method
[java] at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
[java] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
[java] at java.lang.Thread.run(Thread.java:748)
[java] Caused by: java.lang.IllegalStateException: Location is not set.
[java] at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
[java] at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
[java] at main.Main.start(Unknown Source)
[java] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
[java] at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
[java] at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
[java] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
[java] at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
[java] at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
[java] ... 1 more
[java] Exception running application main.Main
[java] Java Result: 1
From what I've found online, this error occurs, when the project's .fxml file can't be found.
This only occurs when I try to use ant to run the program. When I run it using intelliJ IDE everything works just fine. I've even reproduced this error when running the program using IDE by giving it wrong .fxml resource url. So I guess that ant just can't find the fxml file, hovewer I am lost in this regard and dont know how to make my build.xml find the .fxml.
This is my build.xml file:
<project name="ija-app" basedir=".">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="jar.dir" value="dest"/>
<property name="lib.dir" value="lib"/>
<property name="main-class" value="main.Main"/>
<path id="classpath">
<pathelement location="${lib.dir}/jackson-annotations-2.9.0.jar"/>
<pathelement location="${lib.dir}/jackson-core-2.9.9.jar"/>
<pathelement location="${lib.dir}/jackson-databind-2.9.9.jar"/>
<pathelement location="${lib.dir}/jackson-dataformat-yaml-2.9.9.jar"/>
<pathelement location="${lib.dir}/snakeyaml-1.23.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}/*"/>
<delete file="${lib.dir}/*.jar"/>
</target>
<target name="compile" depends="clean">
<exec executable="/bin/bash">
<arg value="./lib/get-libs.sh"/>
</exec>
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<path refid="classpath"/>
</classpath>
</javac>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar"/>
</jar>
</target>
<target name="docs" depends="compile">
<javadoc soudepath="${src.dir}" destdir="${doc.dir}">
<classpath>
<path refid="classpath"/>
</classpath>
</javadoc>
</target>
<target name="run">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
</project>
Thanks for any tips on how to get it running.