Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 6c47093

Browse files
committed
Document executable JAR to native
Closes gh-736 Closes gh-738
1 parent 5090313 commit 6c47093

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[[executable-jar-to-native]]
2+
== Executable JAR to native
3+
4+
It is possible to turn a https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-executable-jar-format.html[Spring Boot executable JAR] to a native executable or a container image containing a native executable. This can be useful for various use cases:
5+
6+
* Keep the regular JVM pipeline and turn the JVM Spring Boot application to native on the CI/CD platform.
7+
* Keep an architecture neutral deployment artifact (`native-image` https://github.com/oracle/graal/issues/407[does not support cross-compilation]).
8+
9+
WARNING: A mandatory pre-requisite is to use <<spring-aot>> Maven or Gradle upstream to build the Spring Boot executable JAR.
10+
11+
=== With Buildpacks
12+
13+
With Spring Boot, https://buildpacks.io/[Buildpacks] is usually used with the Maven (`mvn spring-boot:build-image`) or Gradle (`gradle bootBuilImage`) integration. But you can also use directly https://buildpacks.io/docs/tools/pack/[the `pack` CLI] to turn a Spring Boot executable JAR built with <<spring-aot>> into an optimized container image:
14+
15+
* Prerequisite: a Docker daemon needs to be available, https://hub.docker.com/search?type=edition&offering=community[locally] or https://buildpacks.io/docs/app-developer-guide/build-a-windows-app/#using-remote-docker-hosts[remotely].
16+
* https://buildpacks.io/docs/tools/pack/[Install `pack`].
17+
* Adapt to your project and run `pack build --builder paketobuildpacks/builder:tiny --path target/my-app-0.0.1-SNAPSHOT.jar --env 'BP_NATIVE_IMAGE=true' my-app:0.0.1`
18+
19+
NOTE: This does not require a local `native-image` installation.
20+
21+
=== With `native-image`
22+
23+
Another option is to turn a Spring Boot executable JAR built with <<spring-aot>> into a native executable using GraalVM `native-image` compiler:
24+
25+
* <<getting-started-native-image-system-requirements,Install native-image>>.
26+
* Adapt to your project and run:
27+
28+
```
29+
#!/usr/bin/env bash
30+
31+
rm -rf target/native-image
32+
mkdir -p target/native-image
33+
cd target/native-image
34+
jar -xvf ../my-app-0.0.1-SNAPSHOT-exec.jar >/dev/null 2>&1
35+
cp -R META-INF BOOT-INF/classes
36+
native-image -H:Name=my-app -cp BOOT-INF/classes:`find BOOT-INF/lib | tr '\n' ':'`
37+
mv my-app ../
38+
```
39+
40+
NOTE: This is documented as a simple bash script but can be adapted to whatever is suitable to you environment.

spring-native-docs/src/main/asciidoc/getting-started-buildpacks.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is a practical guide that uses the https://spring.io/guides/gs/rest-service
66

77
TIP: The easiest way to start a new native Spring Boot project is to go to https://start.spring.io, add the "Spring Native" dependency and generate the project.
88

9+
[[getting-started-buildpacks-system-requirements]]
910
==== System Requirements
1011

1112
Docker should be installed, see https://docs.docker.com/installation/#installation[Get Docker] for more details. https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user[Configure it to allow non-root user] if you are on Linux.

spring-native-docs/src/main/asciidoc/getting-started-native-image.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is a practical guide that uses the https://spring.io/guides/gs/rest-service
66

77
NOTE: There is not yet an official native image Gradle plugin, that's why this section is only about Maven. You can vote and subscribe to https://github.com/oracle/graal/issues/3302[graal/issue3302] if you are interested about building native images with Gradle without <<getting-started-buildpacks, using Buildpacks>>.
88

9+
[[getting-started-native-image-system-requirements]]
910
==== System Requirements
1011

1112
A number of {graalvm-native-docs}/#prerequisites[prerequisites] are required before installing the GraalVM `native-image` compiler.

spring-native-docs/src/main/asciidoc/index.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ include::native-image-options.adoc[]
7373

7474
include::tracing-agent.adoc[]
7575

76+
include::executable-jar-to-native.adoc[]
77+
7678
include::troubleshooting.adoc[]
7779

7880
include::how-to-contribute.adoc[]

0 commit comments

Comments
 (0)