13.4. Ant

使用Apache Ant+Ivy构建Spring Boot项目是完全可能的。spring-boot-antlib AntLib模块能够帮助Ant创建可执行jars,一个传统的用于声明依赖的ivy.xml文件可能如下所示:

  1. <ivy-module version="2.0">
  2. <info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
  3. <configurations>
  4. <conf name="compile" description="everything needed to compile this module" />
  5. <conf name="runtime" extends="compile" description="everything needed to run this module" />
  6. </configurations>
  7. <dependencies>
  8. <dependency org="org.springframework.boot" name="spring-boot-starter"
  9. rev="${spring-boot.version}" conf="compile" />
  10. </dependencies>
  11. </ivy-module>

同样,一个传统的build.xml可能是这样的:

  1. <project
  2. xmlns:ivy="antlib:org.apache.ivy.ant"
  3. xmlns:spring-boot="antlib:org.springframework.boot.ant"
  4. name="myapp" default="build">
  5. <property name="spring-boot.version" value="1.3.0.BUILD-SNAPSHOT" />
  6. <target name="resolve" description="--> retrieve dependencies with ivy">
  7. <ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />
  8. </target>
  9. <target name="classpaths" depends="resolve">
  10. <path id="compile.classpath">
  11. <fileset dir="lib/compile" includes="*.jar" />
  12. </path>
  13. </target>
  14. <target name="init" depends="classpaths">
  15. <mkdir dir="build/classes" />
  16. </target>
  17. <target name="compile" depends="init" description="compile">
  18. <javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" />
  19. </target>
  20. <target name="build" depends="compile">
  21. <spring-boot:exejar destfile="build/myapp.jar" classes="build/classes">
  22. <spring-boot:lib>
  23. <fileset dir="lib/runtime" />
  24. </spring-boot:lib>
  25. </spring-boot:exejar>
  26. </target>
  27. </project>

如果你不想使用spring-boot-antlib模块,那查看Section 81.10, “Build an executable archive from Ant without using spring-boot-antlib”获取更多指导。