Friday, September 4, 2020

Ant compile JavaFX project which depends on another one

Oracle Doc said that JavaFX Ant tasks and the JavaFX Packager tool are currently the only supported ways to package JavaFX applications.


I have a JavaFX project client which depends on another common project tool. Under project client, the ant build.xml as below:


<?xml version="1.0" encoding="UTF-8" ?>

 

<project name="Atlas Tool Server" default="default" basedir="."

  xmlns:fx="javafx:com.sun.javafx.tools.ant">

 

  <property name="JAVA_HOME" value="C:\\Program Files\\Java\\jdk1.8.0_261"/>

  <property name="build.src.dir" value="src"/>

  <property name="build.classes.dir" value="classes"/>

  <property name="build.dist.dir" value="dist"/>

  <property name="COMMON_HOME" value="../AtlasTool"/>

  <property name="build.common.src.dir" value="${COMMON_HOME}\\src"/>

 

  <target name="default" depends="clean,compile,copyfile">

 

    <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="AtlasToolServerID"

        name="AtlasToolServerApp"

        mainClass="com.atlasserver.Launcher"/>

 

      <fx:resources id="appRes">

        <fx:fileset dir="${build.dist.dir}" includes="AtlasToolServer.jar"/>

      <fx:fileset dir="${build.dist.dir}" includes="DatabaseConfig.properties"/>

  <fx:fileset dir="${build.dist.dir}">

  <include name="lib/**" />

  </fx:fileset>

      </fx:resources>

 

      <fx:jar destfile="${build.dist.dir}/AtlasToolServer.jar">

        <fx:application refid="AtlasToolServerID"/>

        <fx:resources refid="appRes"/>

        <fileset dir="${build.classes.dir}"/>

      </fx:jar>

 

      <fx:deploy width="300" height="250"

        outdir="." embedJNLP="true"

        outfile="atlastoolclient" nativeBundles="all">

 

        <fx:application refId="AtlasToolServerID"/>

 

        <fx:resources refid="appRes"/>

 

        <fx:info title="Atlas Tool Server"

          vendor="bq"/>

 

      </fx:deploy>

 

  </target>

 

  <target name="clean">

    <mkdir dir="${build.classes.dir}"/>

    <mkdir dir="${build.dist.dir}"/>

 

  <!--mkdir dir="${build.classes.dir}/com/atlastool/view"/>

  <mkdir dir="${build.classes.dir}/com/atlasserver/view"/-->


    <delete>

      <fileset dir="${build.classes.dir}" includes="**/*"/>

      <fileset dir="${build.dist.dir}" includes="**/*"/>

    </delete>

 

  </target>

 

  <target name="compile" depends="clean">

  <path id="classpath">

          <fileset dir="${COMMON_HOME}/lib">

              <include name="*.jar"/>

          </fileset>

  </path>

    <javac includeantruntime="false"

      srcdir="${build.src.dir}:${build.common.src.dir}"

      destdir="${build.classes.dir}"

      fork="yes"

      executable="${JAVA_HOME}/bin/javac"

      source="1.8"

      debug="on"

      encoding="UTF-8">

    <classpath refid="classpath"/>

    </javac>

  </target>

 

  <target name="copyfile" depends="compile">

  <copy todir="${build.classes.dir}">

      <fileset dir="${COMMON_HOME}/resources"/>

  </copy>

 

  <copy todir="${build.dist.dir}/lib">

  <fileset dir="${COMMON_HOME}/lib">

  </fileset>

  </copy>

 

  <copy todir="${build.dist.dir}" file="${COMMON_HOME}/DatabaseConfig.properties"/>

 

  <copy todir="${build.dist.dir}">

  <fileset dir="${COMMON_HOME}">

          <include name="${COMMON_HOME}/DatabaseConfig.properties"/>

  </fileset>

  </copy>

  <copy todir="${build.classes.dir}/com/atlastool/view">

      <fileset dir="${build.common.src.dir}/com/atlastool/view"/>

  </copy>

  <copy todir="${build.classes.dir}/com/atlasserver/view">

      <fileset dir="${build.src.dir}/com/atlasserver/view"/>

  </copy>

</target>

</project>

No comments:

Post a Comment