Create spring-boot-antlib module
Create a new spring-boot-antlib module which allows Apache Ant users to easily create executable jars. Fixes gh-3339
This commit is contained in:
committed by
Phillip Webb
parent
8d948dfa6c
commit
ae4559eb4f
@@ -607,11 +607,155 @@ further information.
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-antlib]]
|
||||
== 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`:
|
||||
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<project xmlns:ivy="antlib:org.apache.ivy.ant"
|
||||
xmlns:spring-boot="antlib:org.springframework.boot.ant"
|
||||
name="myapp" default="build">
|
||||
...
|
||||
</project>
|
||||
----
|
||||
|
||||
You'll need to remember to start Ant using the `-lib` option, for example:
|
||||
|
||||
[indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
$ ant -lib <folder containing spring-boot-antlib-{spring-boot-version}.jar>
|
||||
----
|
||||
|
||||
TIP: The "`Using Spring Boot`" section includes a more complete example of
|
||||
<<using-spring-boot.adoc#using-boot-ant, using Apache Ant with `spring-boot-antlib`>>
|
||||
|
||||
|
||||
=== Spring Boot Ant tasks
|
||||
Once the `spring-boot-antlib` namespace has been declared, the following additional
|
||||
tasks are available.
|
||||
|
||||
|
||||
|
||||
==== spring-boot:exejar
|
||||
The `exejar` task can be used to creates a Spring Boot executable jar. The following
|
||||
attributes are supported by the task:
|
||||
|
||||
[cols="1,2,2"]
|
||||
|====
|
||||
|Attribute |Description |Required
|
||||
|
||||
|`destfile`
|
||||
|The destination jar file to create
|
||||
|Yes
|
||||
|
||||
|`classes`
|
||||
|The root directory of Java classfiles
|
||||
|Yes
|
||||
|
||||
|`start-class`
|
||||
|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:
|
||||
|
||||
[cols="1,4"]
|
||||
|====
|
||||
|Element |Description
|
||||
|
||||
|`resources`
|
||||
|One or more {ant-manual}/Types/resources.html#collection[Resource Collections]
|
||||
describing a set of {ant-manual}/Types/resources.html[Resources] that should be added to
|
||||
the content of the created +jar+ file.
|
||||
|
||||
|`lib`
|
||||
|One or more {ant-manual}/Types/resources.html#collection[Resource Collections]
|
||||
that should be added to the set of jar libraries that make up the runtime dependency
|
||||
classpath of the application.
|
||||
|====
|
||||
|
||||
|
||||
|
||||
===== Examples
|
||||
.Specify +start-class+
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<spring-boot:exejar destfile="target/my-application.jar"
|
||||
classes="target/classes" start-class="com.foo.MyApplication">
|
||||
<resources>
|
||||
<fileset dir="src/main/resources" />
|
||||
</resources>
|
||||
<lib>
|
||||
<fileset dir="lib" />
|
||||
</lib>
|
||||
</spring-boot:exejar>
|
||||
----
|
||||
|
||||
.Detect +start-class+
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<exejar destfile="target/my-application.jar" classes="target/classes">
|
||||
<lib>
|
||||
<fileset dir="lib" />
|
||||
</lib>
|
||||
</exejar>
|
||||
----
|
||||
|
||||
|
||||
|
||||
=== 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
|
||||
|
||||
[cols="1,2,2"]
|
||||
|====
|
||||
|Attribute |Description |Required
|
||||
|
||||
|`classesroot`
|
||||
|The root directory of Java classfiles
|
||||
|Yes _(unless `mainclass` is specified)_
|
||||
|
||||
|`mainclass`
|
||||
|Can be used to short-circuit the `main` class search
|
||||
|No
|
||||
|
||||
|`property`
|
||||
|The Ant property that should be set with the result
|
||||
|No _(result will be logged if unspecified)_
|
||||
|====
|
||||
|
||||
|
||||
|
||||
===== Examples
|
||||
.Find and log
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<findmainclass classesroot="target/classes" />
|
||||
----
|
||||
|
||||
.Find and set
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<findmainclass classesroot="target/classes" property="main-class" />
|
||||
----
|
||||
|
||||
.Override and set
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<findmainclass mainclass="com.foo.MainClass" property="main-class" />
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-other-build-systems]]
|
||||
== Supporting other build systems
|
||||
If you want to use a build tool other than Maven or Gradle, you will likely need to develop
|
||||
your own plugin. Executable jars need to follow a specific format and certain entries need
|
||||
to be written in an uncompressed form (see the
|
||||
If you want to use a build tool other than Maven, Gradle or Ant, you will likely need to
|
||||
develop your own plugin. Executable jars need to follow a specific format and certain
|
||||
entries need to be written in an uncompressed form (see the
|
||||
_<<appendix-executable-jar-format.adoc#executable-jar, executable jar format>>_ section
|
||||
in the appendix for details).
|
||||
|
||||
@@ -668,6 +812,8 @@ Here is a typical example repackage:
|
||||
});
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[build-tool-plugins-whats-next]]
|
||||
== What to read next
|
||||
If you're interested in how the build tool plugins work you can
|
||||
|
||||
@@ -2198,9 +2198,10 @@ details.
|
||||
|
||||
|
||||
[[howto-build-an-executable-archive-with-ant]]
|
||||
=== Build an executable archive with Ant
|
||||
=== 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 as normal. To make it executable:
|
||||
archive as normal. To make it executable you can either use the `spring-boot-antlib`
|
||||
module, or you can follow these instructions:
|
||||
|
||||
. Use the appropriate launcher as a `Main-Class`, e.g. `JarLauncher` for a jar file, and
|
||||
specify the other properties it needs as manifest entries, principally a `Start-Class`.
|
||||
@@ -2236,7 +2237,7 @@ The Actuator Sample has a `build.xml` that should work if you run it with
|
||||
|
||||
[indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
$ ant -lib <path_to>/ivy-2.2.jar
|
||||
$ ant -lib <folder containing ivy-2.2.jar>
|
||||
----
|
||||
|
||||
after which you can run the application with
|
||||
|
||||
@@ -39,6 +39,7 @@ Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson;
|
||||
:spring-data-mongo-javadoc: http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb
|
||||
:spring-data-rest-javadoc: http://docs.spring.io/spring-data/rest/docs/current/api/org/springframework/data/rest
|
||||
:gradle-userguide: http://www.gradle.org/docs/current/userguide
|
||||
:ant-manual: http://ant.apache.org/manual
|
||||
// ======================================================================================
|
||||
|
||||
include::documentation-overview.adoc[]
|
||||
|
||||
@@ -210,12 +210,68 @@ endif::[]
|
||||
|
||||
[[using-boot-ant]]
|
||||
=== Ant
|
||||
It is possible to build a Spring Boot project using Apache Ant, however, no special
|
||||
support or plugins are provided. Ant scripts can use the Ivy dependency system to import
|
||||
starter POMs.
|
||||
It is possible to build a Spring Boot project using Apache Ant+Ivy. The
|
||||
`spring-boot-antlib` "`AntLib`" module is also available to help Ant create executable
|
||||
jars.
|
||||
|
||||
See the _<<howto.adoc#howto-build-an-executable-archive-with-ant>>_ "`How-to`" for more
|
||||
complete instructions.
|
||||
To declare dependencies a typical `ivy.xml` file will look something like this:
|
||||
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
|
||||
<configurations>
|
||||
<conf name="compile" description="everything needed to compile this module" />
|
||||
<conf name="runtime" extends="compile" description="everything needed to run this module" />
|
||||
</configurations>
|
||||
<dependencies>
|
||||
<dependency org="org.springframework.boot" name="spring-boot-starter"
|
||||
rev="${spring-boot.version}" conf="compile" />
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
----
|
||||
|
||||
A typical `build.xml` will look like this:
|
||||
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<project
|
||||
xmlns:ivy="antlib:org.apache.ivy.ant"
|
||||
xmlns:spring-boot="antlib:org.springframework.boot.ant"
|
||||
name="myapp" default="build">
|
||||
|
||||
<property name="spring-boot.version" value="1.3.0.BUILD-SNAPSHOT" />
|
||||
|
||||
<target name="resolve" description="--> retrieve dependencies with ivy">
|
||||
<ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />
|
||||
</target>
|
||||
|
||||
<target name="classpaths" depends="resolve">
|
||||
<path id="compile.classpath">
|
||||
<fileset dir="lib/compile" includes="*.jar" />
|
||||
</path>
|
||||
</target>
|
||||
|
||||
<target name="init" depends="classpaths">
|
||||
<mkdir dir="build/classes" />
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init" description="compile">
|
||||
<javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile">
|
||||
<spring-boot:exejar destfile="build/myapp.jar" classes="build/classes">
|
||||
<spring-boot:lib>
|
||||
<fileset dir="lib/runtime" />
|
||||
</spring-boot:lib>
|
||||
</spring-boot:exejar>
|
||||
</target>
|
||||
</project>
|
||||
----
|
||||
|
||||
TIP: See the _<<howto.adoc#howto-build-an-executable-archive-with-ant>>_ "`How-to`" if
|
||||
you don't want to use the `spring-boot-antlib` module.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user