java - Cannot build JavaFX application using Ant -
i need create build file ant build javafx project, have searched lot, nothing helped me. still show errors compiles. when tries run jar file - exceptions. have tried different paths, still nothing.
here build.xml.
<?xml version="1.0" encoding="utf-8" ?> <project name="jdbc ant project" default="default" basedir="." xmlns:**fx="javafx:com.sun.javafx.tools.ant"**(uri not registered)> <property name="src.dir" location="src"/> <property name="build.dir" location="classes"/> <property name="out.dir" location="out"/> <property name="docs.dir" location="docs"/> <property name="bin.dir" location="bin"/> <property name="lib.dir" location="lib"/> <property name="jar.name" value="javafxtest.jar"/> <property name="sdk.dir" location="/usr/lib/jvm/java-8-oracle/lib"/> <target name="default" depends="clean,compile"> <path id="fxant"> <filelist> <file name="/usr/lib/jvm/java-8-oracle/lib/ant-javafx.jar"/> <file name="/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar"/> </filelist> </path> <*taskdef*(failed load types) resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpathref="fxant"/> <fx:**application** id="helloworldid" name="jdbc java fx" mainclass="main"/> <fx:resources id="appres"> <fx:fileset dir="${out.dir}" includes="helloworld.jar"/> </fx:resources> <fx:jar destfile="${out.dir}/${jar.name}"> <fx:application refid="helloworldid"/> <fx:resources refid="appres"/> <fileset dir="${build.dir}"/> </fx:jar> <fx:**deploy width**="300" **height**="250" **outdir**="." **embedjnlp**="true" **outfile**="helloworld"> <fx:**application** refid="helloworldid"/> <**fx:resources** refid="appres"/> <**fx:info** title="javafx hello world application" vendor="oracle corporation"/> </fx:**deploy**> </target> <target name="clean"> <echo>performing clean target</echo> <delete dir="${build.dir}"/> <delete dir="${docs.dir}"/> <delete dir="${out.dir}"/> </target> <target name="init"> <echo>performing init target</echo> <mkdir dir="${build.dir}"/> <mkdir dir="${docs.dir}"/> <mkdir dir="${out.dir}"/> </target> <target name="compile" depends="clean, init"> <echo>performing compiling</echo> <javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}"> <classpath refid="build.classpath"/> </javac> </target> <path id="build.classpath"> <fileset dir="${lib.dir}" casesensitive="no"> <include name="**/*.jar"/> </fileset> </path> <target name="javadoc" depends="compile"> <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}"> <!-- define files / directory should included, include --> <fileset dir="${src.dir}"> <include name="**"/> <exclude name="**/resources/**"/> </fileset> </javadoc> </target> <target name="build" depends="compile"> <jar destfile="${out.dir}/${jar.name}" basedir="${build.dir}"> <manifest> <attribute name="main-class" value="main"/> </manifest> </jar> </target> <target name="main" depends="compile, build, javadoc"> <description>main target</description> </target> </project>
** "red" in idea (intellij idea.
* underlined .
but nevertheless builds using ant -f build.xml. when tries run jar file getting next exceptions. exception in application start method
java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ..... ..... caused by: java.lang.illegalstateexception: location not set. @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:2438) @ javafx.fxml.fxmlloader.load(fxmlloader.java:2413) @ main.start(unknown source)
update on copying resources using javafx ant tasks
there no folder fxml, css , other files in output jar file. if put manually works, how ant exlictly include folder ?
based on java deployment tutorial javafx ant tasks helloworld build.xml sample, , modifying add resources
directory (which sibling project src
, classes
, dist
directories). place fxml
, css
in resources
directory them included in jar. directory structure of copied files match directory structure of resources directory, if put them in resources directory no sub-directories, files show in root of jar file (so when use resources reference them relative root (e.g. fxmlloader.load(getresource("/main.fxml"))
). made these modifications without testing don't use ant builds anymore.
<property name="build.src.dir" value="src"/> <property name="build.resources.dir" value="resources"/> <property name="build.classes.dir" value="classes"/> <property name="build.dist.dir" value="dist"/> <target name="default" depends="clean,compile"> <taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${java_home}/lib/ant-javafx.jar"/> <fx:application id="helloworldid" name="javafxhelloworldapp" mainclass="helloworld"/> <fx:resources id="appres"> <fx:fileset dir="${build.dist.dir}" includes="helloworld.jar"/> </fx:resources> <fx:jar destfile="${build.dist.dir}/helloworld.jar"> <fx:application refid="helloworldid"/> <fx:resources refid="appres"/> <fileset dir="${build.classes.dir}"/> <fileset dir="${build.resources.dir}"/> </fx:jar> . . . </target>
you have runtime issue not build issue
it seem application builds fine , getting runtime error trying run application, either due issue in application code or because resources required execution not present.
try simpler application not include fxml , build , execute - if works either error in application code or in code copies fxml resources build package.
on intellij syntax highlighting of javafx ant tasks
regarding "uri not registered" error in intellij, bit of red-herring. means haven't registered schema fx namespace idea, idea cannot validate document (and provide context sensitive code completion on xml tags). long haven't made syntax or structure errors in xml (which haven't or ant reject it), can ignore such error messages if wish.
you can find more information on here:
note: don't think oracle provide full xml schema javafx ant tasks, not possible configure idea validate javafx ant task elements of ant build.xml file. however, should not prevent building application - best policy configure idea ignore javafx ant tasks xml schema, no longer displays annoying , misdirecting red highlights on build.xml file.
alternative technology
you may (or may not) find using javafx maven plugin or javafx gradle plugin better solution using javafx ant tasks directly.
Comments
Post a Comment