启用 AOT 编译打包
启用 AOT 编译打包后,在打包时会给动态代理类生成对应具体类(类名风格,Xxx$$SolonAotProxy.class)。且,不再需要 ASM 介入生成。AOT 编译,为 Native 编译打包的一部分,可以独立使用。
使用条件要求:
- 使用 solon-maven-plugin 打包方式
- 要求 java 17+ (java 17 后才支持 AOT)
1、使用 solon-parent
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>最新版本</version>
</parent>
以 maven 打包为例,启用配置文件 native,然后使用 maven 的 pakage 命令即可。
补充说明:
- 使用 maven:pakage 打包,会使用 AOT 编译,生成常规的 jar 包
- 使用 graalvm:native:build 打包,会使用 AOT 编译,且生成 graalvm image (具体参考专题资料)
2、没有使用 solon-parent
以 maven 打包为例,在 pom.xml 添加一个 profile。之后,参考上面的说明。
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.noear</groupId>
<artifactId>solon-maven-plugin</artifactId>
<version>${solon.version}</version>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-aot</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>