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/classes
directory. If you are building a war, package the application’s classes in a nestedWEB-INF/classes
directory as usual. - Add the runtime dependencies in a nested
BOOT-INF/lib
directory for a jar orWEB-INF/lib
for a war. Remember not to compress the entries in the archive. - Add the
provided
(embedded container) dependencies in a nestedBOOT-INF/lib
directory for jar orWEB-INF/lib-provided
for a war. Remember not to compress the entries in the archive. - Add the
spring-boot-loader
classes at the root of the archive (so theMain-Class
is available). - Use the appropriate launcher, e.g.
JarLauncher
for a jar file, as aMain-Class
attribute 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