Building
此部分介绍如何构建 Spring Shell 应用程序。
This section covers how to build a Spring Shell application.
Native Support
对于将 Spring Shell 应用程序编译成 GraalVM 二进制文件,支持主要是来自于 Spring Framework 和 Spring Boot,其中功能被称为 AOT。即时编译是指在编译时准备应用程序上下文以准备好进行 GraalVM 生成。
Support for compiling Spring Shell application into a GraalVM binary mostly comes from Spring Framework and Spring Boot where feature is called AOT. Ahead of Time means that application context is prepared during the compilation time to being ready for GraalVM generation.
在框架 Spring Shell 的 AOT 功能基础上构建,GraalVM 配置提供了提示,说明二进制文件中应该存在什么。问题通常来自尚未包含 GraalVM 相关配置或这些配置不完整的第三方库。
Building atop of AOT features from a framework Spring Shell has its own GraalVM configuration providing hints what should exist in a binary. Usually trouble comes from a 3rd party libraries which doesn’t yet contain GraalVM related configurations or those configurations are incomplete.
必需使用 GraalVM Reachability Metadata Repository,它为第三方库提供了一些缺失的提示。此外,还需要安装 GraalVM,并且 JAVA_HOME
指向该库。
It is requred to use GraalVM Reachability Metadata Repository which
provides some missing hints for 3rd party libraries. Also you need to have
GraalVM installed and JAVA_HOME
pointing to that.
对于 gradle,添加 graalvm 的原生插件和配置元数据存储库。
For gradle add graalvm’s native plugin and configure metadata repository.
plugins {
id 'org.graalvm.buildtools.native' version '0.9.16'
}
graalvmNative {
metadataRepository {
enabled = true
}
}
在使用 ./gradlew nativeCompile
运行 gradle build 时,你应该会在 build/native/nativeCompile
目录下获取二进制文件。
When gradle build is run with ./gradlew nativeCompile
you should get binary
under build/native/nativeCompile
directory.
对于 maven
,使用 spring-boot-starter-parent
作为其父,你将获取 `native`profile,可用于编译。你需要配置元数据存储库。
For maven
use spring-boot-starter-parent
as parent and you’ll get native
profile which can be used to do a compilation. You need to configure metadata repository
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
如果您依赖 |
If you rely on |
在使用 ./mvnw native:compile -Pnative
运行 maven build 时,你应该会在 target
目录下获取二进制文件。
When maven build is run with ./mvnw native:compile -Pnative
you should get binary
under target
directory.
如果一切顺利,该二进制文件可以像预期的那样运行,不必通过 jvm 执行 boot 应用程序 jar。
If everything went well this binary can be run as is instead of executing boot application jar via jvm.