|
| 1 | +### 13.4. Ant |
| 2 | + |
| 3 | +使用Apache Ant+Ivy构建Spring Boot项目是完全可能的。`spring-boot-antlib` AntLib模块能够帮助Ant创建可执行jars,一个传统的用于声明依赖的`ivy.xml`文件可能如下所示: |
| 4 | +```xml |
| 5 | +<ivy-module version="2.0"> |
| 6 | + <info organisation="org.springframework.boot" module="spring-boot-sample-ant" /> |
| 7 | + <configurations> |
| 8 | + <conf name="compile" description="everything needed to compile this module" /> |
| 9 | + <conf name="runtime" extends="compile" description="everything needed to run this module" /> |
| 10 | + </configurations> |
| 11 | + <dependencies> |
| 12 | + <dependency org="org.springframework.boot" name="spring-boot-starter" |
| 13 | + rev="${spring-boot.version}" conf="compile" /> |
| 14 | + </dependencies> |
| 15 | +</ivy-module> |
| 16 | +``` |
| 17 | +同样,一个传统的`build.xml`可能是这样的: |
| 18 | +```xml |
| 19 | +<project |
| 20 | + xmlns:ivy="antlib:org.apache.ivy.ant" |
| 21 | + xmlns:spring-boot="antlib:org.springframework.boot.ant" |
| 22 | + name="myapp" default="build"> |
| 23 | + |
| 24 | + <property name="spring-boot.version" value="1.3.0.BUILD-SNAPSHOT" /> |
| 25 | + |
| 26 | + <target name="resolve" description="--> retrieve dependencies with ivy"> |
| 27 | + <ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" /> |
| 28 | + </target> |
| 29 | + |
| 30 | + <target name="classpaths" depends="resolve"> |
| 31 | + <path id="compile.classpath"> |
| 32 | + <fileset dir="lib/compile" includes="*.jar" /> |
| 33 | + </path> |
| 34 | + </target> |
| 35 | + |
| 36 | + <target name="init" depends="classpaths"> |
| 37 | + <mkdir dir="build/classes" /> |
| 38 | + </target> |
| 39 | + |
| 40 | + <target name="compile" depends="init" description="compile"> |
| 41 | + <javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" /> |
| 42 | + </target> |
| 43 | + |
| 44 | + <target name="build" depends="compile"> |
| 45 | + <spring-boot:exejar destfile="build/myapp.jar" classes="build/classes"> |
| 46 | + <spring-boot:lib> |
| 47 | + <fileset dir="lib/runtime" /> |
| 48 | + </spring-boot:lib> |
| 49 | + </spring-boot:exejar> |
| 50 | + </target> |
| 51 | +</project> |
| 52 | +``` |
| 53 | + |
| 54 | +**注** 如果你不想使用`spring-boot-antlib`模块,那查看[Section 81.10, “Build an executable archive from Ant without using spring-boot-antlib”](../IX. ‘How-to’ guides/73.8. Build an executable archive with Ant.md)获取更多指导。 |
0 commit comments