1 Star 4 Fork 3

OpenSolon/solon-native-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
西东 demo 875c47b 7个月前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

solon graalvm native

本项目是一个 将solon打包成 native 可执行程序 的示例

1、环境要求

graalvm 17 & native-image

graalvm 17

官方安装文档:https://www.graalvm.org/latest/docs/getting-started/#install-graalvm

下载地址:https://github.com/graalvm/graalvm-ce-builds/releases

下载对应的版本,建议使用 sdkman ( 安装地址:https://sdkman.io/ ) 来管理不同的jdk版本

# 最新版本为:17.0.8-graalce,可以在下载地址中查看最新版本
sdk install java 17.0.8-graalce

# 使用 17.0.8-graalce 版本
sdk use java 17.0.8-graalce

native-image

官方安装文档:https://www.graalvm.org/latest/reference-manual/native-image/#install-native-image

gu install native-image

2、打包成 jar

用 install 可以兼容多模块场景,用 package 只适合单模块

mvn clean install -DskipTests

3、打包成 native 可执行程序

  1. 引入依赖(本项目已经引入)
<!--solon aot start(用于 aot 时注册 native 元信息)-->
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon.aot</artifactId>
</dependency>
<!--solon aot end-->
  1. 激活 native 的 profile,执行mvn命令
sdk use java 17.0.7-graal

# 打包成native可执行程序
mvn clean native:compile -P native -DskipTests

# 运行可执行成
./target/solon-native-example

4、测试

GET http://localhost:8080/hello?name=solon

GET http://localhost:8080/hello/tml?name=solon

GET http://localhost:8080/htm/hello.htm

remote

GET http://localhost:8080/rpc/v1/user/getById?userId=11

GET http://localhost:8080/rpc/v1/user/addOrder?orderId=12

响应:

{
  "@type": "com.github.dudiao.solon.demo.User",
  "user_name": "dudiao",
  "wxid": "11"
}

service 带缓存

GET http://localhost:8080/cache/say?msg=你好

响应:I want say: 你好, now: 2023-04-15 17:01:09

参数msg不变,响应不变,说明缓存生效

Mybatis native

GET http://localhost:8080/user/1

5、关于 graalvm native 的一些说明

当使用一个新的第三方包时,不知道第三方包中哪些地方使用了反射等 graalvm 不支持的特性,可以使用agentlib:native-image-agent来生成配置文件,然后在native-image命令中引入配置文件,这样就可以解决第三方包中的问题了

-agentlib:native-image-agent=config-output-dir=/Users/xxx/study/solon-native-example/target/tracing-agent

6、三方包的一些不支持项

spring-boot 已经踩了很多坑了,可以作为参考:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-GraalVM

MIT License Copyright (c) 2024 noear Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

本项目是一个 将solon打包成 native 可执行程序 的示例 展开 收起
Java 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/opensolon/solon-native-example.git
git@gitee.com:opensolon/solon-native-example.git
opensolon
solon-native-example
solon-native-example
master

搜索帮助