Created
April 13, 2015 17:16
-
-
Save sivajankan/3efd3114f23d8b71f4f3 to your computer and use it in GitHub Desktop.
OneJar Ant Build XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project name="YourProjectName" default="jar" basedir="."> | |
| <target name="init"> | |
| <property name="version" value="1.0.0" /> | |
| <property name="debuglevel" value="source,lines,vars"/> | |
| <property name="main-class" value="com.company.project.mainclass"/> | |
| <property name="src.dir" value="src"/> | |
| <property name="build.dir" value="build"/> | |
| <property name="classes.dir" value="${build.dir}/classes"/> | |
| <property name="lib.dir" value="lib" /> | |
| <!-- put all dependencies libraries in ./lib folder --> | |
| <path id="Build Dependencies Classpath"> | |
| <fileset dir="${lib.dir}"> | |
| <include name="**/*.jar"/> | |
| </fileset> | |
| </path> | |
| <!-- needed for dev run --> | |
| <path id="Run application" location="./${lib.dir}" /> | |
| <tstamp> | |
| <format property="timestamp" pattern="yyyy-MM-dd HH:mm:ss" /> | |
| </tstamp> | |
| </target> | |
| <!-- clean build dir --> | |
| <target name="clean" depends="init"> | |
| <delete dir="${build.dir}"/> | |
| </target> | |
| <!-- compile codes and put in classes dir (build/classes) and use classpath --> | |
| <target name="compile" depends="clean"> | |
| <mkdir dir="${classes.dir}"/> | |
| <javac srcdir="${src.dir}" | |
| destdir="${classes.dir}" | |
| includeAntRuntime="false" | |
| debug="true" debuglevel="${debuglevel}"> | |
| <classpath refid="Build Dependencies Classpath"/> | |
| </javac> | |
| </target> | |
| <!-- build main jar file --> | |
| <target name ="jar" depends="compile"> | |
| <!--copy properties file --> | |
| <copy includeemptydirs="false" todir="${build.dir}/classes"> | |
| <fileset dir="${src.dir}"> | |
| <exclude name="**/*.java"/> | |
| </fileset> | |
| </copy> | |
| <!--Build main jar--> | |
| <jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"> | |
| <manifest> | |
| <attribute name="Main-Class" value="${main-class}"/> | |
| <attribute name="Build-Version" value="${version}"/> | |
| <attribute name="Build-Date" value="${timestamp}"/> | |
| </manifest> | |
| </jar> | |
| </target> | |
| <!--only aimed to run in dev env --> | |
| <target name="run" depends="jar"> | |
| <java jar="${ant.project.name}.jar" fork="true"> | |
| <classpath> | |
| <path refid="Build Dependencies Classpath" /> | |
| <path refid="Run application" /> | |
| </classpath> | |
| </java> | |
| </target> | |
| <!-- build one jar file --> | |
| <taskdef name="one-jar" classname="com.simontuffs.onejar.ant.OneJarTask" onerror="report" /> | |
| <target name="onejar" depends="jar"> | |
| <!-- Construct the One-JAR file --> | |
| <one-jar destfile="${ant.project.name}Exec.jar"> | |
| <manifest> | |
| <attribute name="One-Jar-Main-Class" value="${main-class}"/> | |
| <attribute name="Build-Version" value="${version}"/> | |
| <attribute name="Build-Date" value="${timestamp}"/> | |
| </manifest> | |
| <main jar="${ant.project.name}.jar" /> | |
| <lib> | |
| <fileset dir="${lib.dir}" /> | |
| </lib> | |
| </one-jar> | |
| </target> | |
| <!-- run one jar file --> | |
| <target name="run onejar" depends="onejar"> | |
| <java jar="${ant.project.name}Exec.jar" fork="true" /> | |
| </target> | |
| </project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment