Ref
ant tutorial
ivy tutorial
repository
projects folder
build -classes -jar
src -package -java file
lib */.jar
cmmand lines
ant -p
ant resolve
ant compile jar run
ant junit #run junit test
build.xml
<!-- build.xml -->
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="hello-ivy" default="run">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="oata.Helloworld"/>
<property name="lib.dir" value="lib"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" >
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<!-- <target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>/>
</target> -->
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
</java>
</target>
<target name="junit" depends="jar">
<junit printsummary="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="**/*Test.java"/>
</batchtest>
</junit>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
ivy.xml
<!-- ivy.xml -->
<ivy-module version="2.0">
<info organisation="org.apache" module="hello-ivy"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
<dependency org="commons-cli" name="commons-cli" rev="1.0"/>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency org="org.junit.jupiter" name="junit-jupiter-api" rev="5.8.2"/>
<dependency org="org.springframework.boot" name="spring-boot-starter-mail" rev="2.3.7.RELEASE"/>
</dependencies>
</ivy-module>
说明:
1.project folder下包含build.xml, ivy.xml文件
2.样例build.xml中有ivy dependencies, 含junit测试, external library
3.替换main-class value
4.ivy.xml中加repository,见repository