68. Spring Boot AntLib module

The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant. You can use the module to create executable jars. To use the module you need to declare an additional spring-boot namespace in your build.xml:

<project xmlns:ivy="antlib:org.apache.ivy.ant"
    name="myapp" default="build">

You’ll need to remember to start Ant using the -lib option, for example:

$ ant -lib <folder containing spring-boot-antlib-1.5.6.RELEASE.jar>

The “Using Spring Boot” section includes a more complete example of using Apache Ant with spring-boot-antlib

68.1 Spring Boot Ant tasks

Once the spring-boot-antlib namespace has been declared, the following additional tasks are available.

68.1.1 spring-boot:exejar

The exejar task can be used to creates a Spring Boot executable jar. The following attributes are supported by the task:



The destination jar file to create



The root directory of Java class files



The main application class to run

No (default is first class found declaring a main method)

The following nested elements can be used with the task:



One or more Resource Collections describing a set of Resources that should be added to the content of the created jar file.


One or more Resource Collections that should be added to the set of jar libraries that make up the runtime dependency classpath of the application.

68.1.2 Examples

Specify start-class. 

<spring-boot:exejar destfile="target/my-application.jar"
        classes="target/classes" start-class="com.foo.MyApplication">
        <fileset dir="src/main/resources" />
        <fileset dir="lib" />

Detect start-class. 

<exejar destfile="target/my-application.jar" classes="target/classes">
        <fileset dir="lib" />

68.2 spring-boot:findmainclass

The findmainclass task is used internally by exejar to locate a class declaring a main. You can also use this task directly in your build if needed. The following attributes are supported



The root directory of Java class files

Yes (unless mainclass is specified)


Can be used to short-circuit the main class search



The Ant property that should be set with the result

No (result will be logged if unspecified)

68.2.1 Examples

Find and log. 

<findmainclass classesroot="target/classes" />

Find and set. 

<findmainclass classesroot="target/classes" property="main-class" />

Override and set. 

<findmainclass mainclass="com.foo.MainClass" property="main-class" />