80.10 Build an executable archive from Ant without using spring-boot-antlib
To build with Ant you need to grab dependencies, compile and then create a jar or war archive. To make it executable you can either use the spring-boot-antlib module, or you can follow these instructions:
- If you are building a jar, package the application’s classes and resources in a nested
BOOT-INF/classesdirectory. If you are building a war, package the application’s classes in a nestedWEB-INF/classesdirectory as usual. - Add the runtime dependencies in a nested
BOOT-INF/libdirectory for a jar orWEB-INF/libfor a war. Remember not to compress the entries in the archive. - Add the
provided(embedded container) dependencies in a nestedBOOT-INF/libdirectory for jar orWEB-INF/lib-providedfor a war. Remember not to compress the entries in the archive. - Add the
spring-boot-loaderclasses at the root of the archive (so theMain-Classis available). - Use the appropriate launcher, e.g.
JarLauncherfor a jar file, as aMain-Classattribute in the manifest and specify the other properties it needs as manifest entries, principally aStart-Class.
Example:
<target name="build" depends="compile">
<jar destfile="target/${ant.project.name}-${spring-boot.version}.jar" compress="false">
<mappedresources>
<fileset dir="target/classes" />
<globmapper from="*" to="BOOT-INF/classes/*"/>
</mappedresources>
<mappedresources>
<fileset dir="src/main/resources" erroronmissingdir="false"/>
<globmapper from="*" to="BOOT-INF/classes/*"/>
</mappedresources>
<mappedresources>
<fileset dir="${lib.dir}/runtime" />
<globmapper from="*" to="BOOT-INF/lib/*"/>
</mappedresources>
<zipfileset src="${lib.dir}/loader/spring-boot-loader-jar-${spring-boot.version}.jar" />
<manifest>
<attribute name="Main-Class" value="org.springframework.boot.loader.JarLauncher" />
<attribute name="Start-Class" value="${start-class}" />
</manifest>
</jar>
</target>
The Ant Sample has a build.xml with a manual task that should work if you run it with
$ ant -lib <folder containing ivy-2.2.jar> clean manual
after which you can run the application with
$ java -jar target/*.jar