Skip to content

Commit d5f2017

Browse files
committed
Frist commit
1 parent 5dfb0ca commit d5f2017

File tree

26 files changed

+929
-62
lines changed

26 files changed

+929
-62
lines changed

.gitignore

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
# Build and Release Folders
2-
bin-debug/
3-
bin-release/
4-
[Oo]bj/
5-
[Bb]in/
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
66

7-
# Other files and folders
8-
.settings/
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
915

10-
# Executables
11-
*.swf
12-
*.air
13-
*.ipa
14-
*.apk
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
1521

16-
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
17-
# should NOT be excluded as they contain compiler settings and other important
18-
# information for Eclipse / Flash Builder.
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/

README.en.md

+118-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,130 @@
11
# java-graalvm-start
22

3-
#### Description
4-
GraalVM最佳实践,使用Java开发CLI、Desktop(JavaFX)、Web(StringBoot)项目,并使用native-image技术把Java代码静态编译为独立可执行文件(本机映像)。
3+
## Description
4+
Graal VM best practice, use Java to develop CLI, Desktop (Java FX), Web (String Boot) projects, and use native-image technology to statically compile Java code into independent executable files (native images).
55

6-
#### Software Architecture
7-
Software architecture description
6+
## Module overview
87

9-
#### Installation
8+
> The performance test results are related to the machine configuration, especially the time-consuming compilation of `native-image`.
109
11-
1. xxxx
12-
2. xxxx
13-
3. xxxx
10+
| ↓Tag \ Module→ | [cli-normal](cli-normal) | [desktop-javafx](desktop-javafx) | [web-springboot](web-springboot) |
11+
| ----- | ----- | ----- | ----- |
12+
| Module desc | Command line app (no framework) | Desktop app (JavaFx) | Web app (SpringBoot) |
13+
| JDK | 8 or 11+ | 11+ | 8 or 11+ |
14+
| GraalVM | CE-21.0.0.2+ | CE-21.0.0.2+ | CE-21.0.0.2+ |
15+
| Maven Plugin | [native-image-maven-plugin](https://www.graalvm.org/reference-manual/native-image/NativeImageMavenPlugin/) | [client-maven-plugin](https://docs.gluonhq.com/#_the_gluon_client_plugin_for_maven) | [native-image-maven-plugin](https://www.graalvm.org/reference-manual/native-image/NativeImageMavenPlugin/) |
16+
| Time-consuming to start (jvm) | 0.713s | 2.555s | 1.793s |
17+
| Time-consuming to start (native-image) | 0.047s | 0.665s | 0.216s |
18+
| Time-consuming to start (native-image) | 24.786s | 93.455s | 99.434s |
19+
| Executable file size (7z compression) | 8.03m (7z : 1.68m) | 62.7m (7z : 13.1m) | 66.5m (7z : 13.9m) |
1420

15-
#### Instructions
21+
## Development environment
1622

17-
1. xxxx
18-
2. xxxx
19-
3. xxxx
23+
> The following is the development environment of my machine. In theory, windows, linux and mac are all supported (note that the dependencies of GraalVM SDK and native-image of different platforms are different).
2024
21-
#### Contribution
25+
- Windows 10 (CPU: i7-7700, RAM: 16G)
26+
- IntelliJ IDEA 2020
27+
- jdk-11.0.10 `In fact, you don’t need to, because GraalVM comes with OpenJDK`
28+
- graalvm-ce-java11-21.0.0.2
29+
- Visual Sutdio 2019
2230

23-
1. Fork the repository
24-
2. Create Feat_xxx branch
25-
3. Commit your code
26-
4. Create Pull Request
31+
## Environment configuration (Windows)
2732

33+
> Needless to say, System, IDE, and JDK, just skip...
2834
29-
#### Gitee Feature
35+
**Graal VM**
36+
- [Download Graal VM SDK](https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-21.0.0.2)
37+
- Set GraalVM environment variables (note that JAVA_HOME also points to GRAALVM_HOME):
38+
``` bat
39+
GRAALVM_HOME = C:\path\to\graalvm-ce-java11-21.0.0.2
40+
JAVA_HOME = %GRAALVM_HOME%
41+
PATH += %GRAALVM_HOME%\bin
42+
```
43+
- Verify the environment `java -version`
44+
```
45+
C:\Users\Administrator>java -version
46+
openjdk version "11.0.10" 2021-01-19
47+
OpenJDK Runtime Environment GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06)
48+
OpenJDK 64-Bit Server VM GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06, mixed mode, sharing)
49+
```
50+
- Install native-image components
51+
``` bat
52+
gu install native-image
53+
```
54+
- Verification component
55+
``` bat
56+
gu list
57+
native-image --version
58+
```
3059

31-
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32-
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33-
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34-
4. The most valuable open source project [GVP](https://gitee.com/gvp)
35-
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36-
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
60+
**MSVC (Visual Studio 2019)**
61+
62+
> In addition to GraalVM, Microsoft Visual Studio 2019 is also required. The community version is enough, You can [download it from here](https://visualstudio.microsoft.com/downloads/)
63+
64+
During the installation process, make sure to select at least the following individual components:
65+
66+
- Choose the English Language Pack
67+
- C++/CLI support for v142 build tools (14.25 or later)
68+
- MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.25 or later)
69+
- Windows Universal CRT SDK
70+
- Windows 10 SDK (10.0.19041.0 or later)
71+
72+
> All build commands, be it with Maven or Gradle, must be executed in a Visual Studio 2019 Command Prompt called x64 Native Tools Command Prompt for VS 2019. A shortcut can be found in the "Start Menu", or you can search the application in the search box. Read the Microsoft documentation for more information.
73+
>
74+
> Alternatively, you can run `cmd.exe /k "<path to VS2019>\VC\Auxiliary\Build\vcvars64.bat` from any other terminal before you can start using the build commands.
75+
76+
> **Recommend this ultimate solution: [Visual Studio 2019 configure MSVC environment variables, use the command line to compile](https://www.jianshu.com/p/7fab25165f4b),In this way, MSVC compilation tools can be used directly on any terminal.**
77+
>
78+
> Be sure to use this ultimate solution, otherwise it will become very troublesome in the build project. Every time before `mvn package`, you must execute `cmd.exe k "<path to VS2019>\VC\Auxiliary\ Build\vcvars64.bat`.
79+
80+
## Environment configuration(Linux/Mac)
81+
82+
**Linux**
83+
84+
Download Graal VM and configure environment variables. In addition to Graal VM, the following software packages are also required:
85+
86+
- gcc version 6 or higher
87+
- ld version 2.26 or higher
88+
89+
**Mac**
90+
91+
- TODO
92+
93+
For a more detailed description of different platform configurations and dependencies, please refer to: [Gluon Documentation](https://docs.gluonhq.com/#_platforms)
94+
95+
> tips:Gluon is a contributor to the `OpenJFX` project and the `GraalVM` project. The company provides `client-maven-plugin` to encapsulate the related commands of `native-image`, which simplifies the packaging operation.
96+
97+
## Precautions
98+
99+
- Through the above steps, you have configured the development environment. Another thing to note is that in IDEA development tools, when you need to set the JDK for the project, you should directly point to the bin directory under GraalVM, not other JDK directories, Otherwise an error may occur during compilation.
100+
101+
## Extended reading
102+
103+
- GraalVM should not support cross-compilation, but you can use the Linux subsystem provided by Windows to compile the source code.
104+
105+
## Follow-up planning
106+
107+
> For other implementations of these three applications, more modules may be added later.
108+
109+
- cli-&lt;A library that supports parsing args parameters> `For faster development of cli applications`
110+
- desktop-&lt;Swing/AWT&gt; `Other GUI implementations`
111+
- web-&lt;Lightweight, containerless http-server library> `Other web implementations`
112+
113+
## Technology Exchange
114+
115+
- QQ Group: [707416319](https://qm.qq.com/cgi-bin/qm/qr?k=uSAXH8sKqQnF_cvDSF4T8IN7tSqabAJ3&jump_from=webapi)
116+
117+
## Reference
118+
119+
- Official information
120+
- [Get Started with GraalVM](https://www.graalvm.org/docs/getting-started/)
121+
- [native-image documentation](https://www.graalvm.org/reference-manual/native-image/)
122+
- [JavaFX website](https://openjfx.io/) `Recommended reading`
123+
- [Spring Native for GraalVM documentation](https://repo.spring.io/milestone/org/springframework/experimental/spring-graalvm-native-docs/0.8.5/spring-graalvm-native-docs-0.8.5.zip!/reference/index.html) `Recommended reading`
124+
- Web articles
125+
- [How to evaluate the GraalVM project?](https://www.zhihu.com/question/274042223) `Recommended reading`
126+
- [Graal VM: Java in the age of microservices](https://www.zhihu.com/column/p/137836206) `Recommended reading` `Very comprehensive explanation`
127+
- [Generate native image for JavaFX application](https://zhuanlan.zhihu.com/p/103606559?utm_source=wechat_session)
128+
- [Use GraalVM under Windows to compile JavaFX applications into exe](https://www.cnblogs.com/dehai/p/14258391.html)
129+
- [Spring Boot as GraalVM Native Images](https://blog.codecentric.de/en/2020/05/spring-boot-graalvm/) `Recommended reading`
130+
- [Spring Boot GraalVM Native Image builds with the native-image-maven-plugin](https://blog.codecentric.de/en/2020/05/spring-boot-graalvm/) `Recommended reading`

README.md

+117-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,131 @@
11
# java-graalvm-start
22

3-
#### 介绍
3+
## 介绍
4+
45
GraalVM最佳实践,使用Java开发CLI、Desktop(JavaFX)、Web(StringBoot)项目,并使用native-image技术把Java代码静态编译为独立可执行文件(本机映像)。
56

6-
#### 软件架构
7-
软件架构说明
7+
## 模块概览
8+
9+
> 其中的性能测试结果与机器配置有关,尤其是 `native-image` 编译耗时。
10+
11+
| ↓标签 \ 模块→ | [cli-normal](cli-normal) | [desktop-javafx](desktop-javafx) | [web-springboot](web-springboot) |
12+
| ----- | ----- | ----- | ----- |
13+
| 模块描述 | 命令行应用(无框架) | 桌面应用(JavaFx) | Web应用(SpringBoot) |
14+
| JDK | 8 or 11+ | 11+ | 8 or 11+ |
15+
| GraalVM | CE-21.0.0.2+ | CE-21.0.0.2+ | CE-21.0.0.2+ |
16+
| Maven Plugin | [native-image-maven-plugin](https://www.graalvm.org/reference-manual/native-image/NativeImageMavenPlugin/) | [client-maven-plugin](https://docs.gluonhq.com/#_the_gluon_client_plugin_for_maven) | [native-image-maven-plugin](https://www.graalvm.org/reference-manual/native-image/NativeImageMavenPlugin/) |
17+
| 启动耗时(jvm) | 0.713s | 2.555s | 1.793s |
18+
| 启动耗时(native-image) | 0.047s | 0.665s | 0.216s |
19+
| 编译耗时(native-image) | 24.786s | 93.455s | 99.434s |
20+
| 可执行文件大小(7z压缩) | 8.03m (7z : 1.68m) | 62.7m (7z : 13.1m) | 66.5m (7z : 13.9m) |
21+
22+
## 开发环境
23+
24+
> 以下是我本机的开发环境,理论上windows、linux、mac都是支持的(注意不同平台的 GraalVM SDK 和 native-image的依赖是不一样的)。
25+
26+
- Windows 10 (CPU: i7-7700, RAM: 16G)
27+
- IntelliJ IDEA 2020
28+
- jdk-11.0.10 `其实也可以不用,因为GraalVM是自带OpenJDK的`
29+
- graalvm-ce-java11-21.0.0.2
30+
- Visual Sutdio 2019
31+
32+
## 环境配置(Windows)
33+
34+
> System、IDE、JDK 这三个就不用说了,直接跳过...
35+
36+
**Graal VM**
37+
- [下载 Graal VM SDK](https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-21.0.0.2)
38+
- 设置GraalVM环境变量(注意JAVA_HOME也要指向GRAALVM_HOME):
39+
``` bat
40+
GRAALVM_HOME = C:\path\to\graalvm-ce-java11-21.0.0.2
41+
JAVA_HOME = %GRAALVM_HOME%
42+
PATH += %GRAALVM_HOME%\bin
43+
```
44+
- 验证环境 `java -version`
45+
```
46+
C:\Users\Administrator>java -version
47+
openjdk version "11.0.10" 2021-01-19
48+
OpenJDK Runtime Environment GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06)
49+
OpenJDK 64-Bit Server VM GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06, mixed mode, sharing)
50+
```
51+
- 安装native-image组件
52+
``` bat
53+
gu install native-image
54+
```
55+
- 验证组件
56+
``` bat
57+
gu list
58+
native-image --version
59+
```
60+
61+
**MSVC (Visual Studio 2019)**
62+
63+
> 除了GraalVM,还需要Microsoft Visual Studio 2019。社区版就足够了,可以从[这里下载](https://visualstudio.microsoft.com/downloads/)
64+
65+
在安装过程中,请确保至少选择以下各个组件:
66+
67+
- 选择英语语言包
68+
- C++/CLI v142 构建工具(14.25或更高版本)
69+
- MSVC v142 - VS 2019 C++ x64/x86 构建工具(v14.25或更高版本)
70+
- Windows 通用 CRT SDK
71+
- Windows 10 SDK(10.0.19041.0或更高版本)
72+
73+
> 所有构建命令(无论是Maven还是Gradle)都必须在名为的Visual Studio 2019命令提示符中执行 `x64 Native Tools Command Prompt for VS 2019`。快捷方式可以在“开始菜单”中找到,也可以在搜索框中搜索应用程序。 阅读Microsoft文档以获取更多信息。
74+
>
75+
> 另外,您可以执行 `cmd.exe /k "<path to VS2019>\VC\Auxiliary\Build\vcvars64.bat` 从任何其他终端运行,然后再开始使用构建命令。
76+
77+
> **推荐这个终极方案:[Visual Studio 2019 配置 MSVC 环境变量,使用命令行编译](https://www.jianshu.com/p/7fab25165f4b),这样就可以在任何终端直接使用MSVC的编译工具。**
78+
>
79+
> 一定要使用这个终极方案,否则在接下来的项目构建中,将会变得很麻烦,每次 `mvn package` 之前都要先执行 `cmd.exe /k "<path to VS2019>\VC\Auxiliary\Build\vcvars64.bat`
80+
81+
## 环境配置(Linux/Mac)
82+
83+
**Linux**
84+
85+
下载GraalVM,配置环境变量,除了GraalVM,还需要以下软件包:
86+
87+
- gcc 6 或更高版本
88+
- ld 2.26 或更高版本
89+
90+
**Mac**
91+
92+
- TODO
93+
94+
有关不同平台配置和依赖更详细的说明,请参考:[Gluon Documentation](https://docs.gluonhq.com/#_platforms)
95+
96+
> tips:Gluon公司是 `OpenJFX` 项目和 `GraalVM` 项目的贡献者,该公司提供了 `client-maven-plugin ` 封装了 `native-image` 的相关命令,简化了打包操作。
97+
98+
## 注意事项
899

100+
- 通过上述步骤,你已经配置好了开发环境,还有一点需要注意的是,在IDEA开发工具中,你需要为项目设置JDK的时候应该直接指向GraalVM下的bin目录,而不是其他JDK的目录,否则在编译时可能会出现错误。
9101

10-
#### 安装教程
102+
## 扩展阅读
11103

12-
1. xxxx
13-
2. xxxx
14-
3. xxxx
104+
- GraalVM应该是不支持交叉编译的,不过可以利用Windows提供的Linux子系统来编译源码。
15105

16-
#### 使用说明
106+
## 后续规划
17107

18-
1. xxxx
19-
2. xxxx
20-
3. xxxx
108+
> 对于这三种应用的其他实现方式,后续可能会添加更多的模块
21109
22-
#### 参与贡献
110+
- cli-<支持解析args参数的库> `用于更快速的开发cli应用`
111+
- desktop-&lt;Swing/AWT> `其他GUI实现方式`
112+
- web-<轻量级无容器的http-server库> `其他Web实现方式`
23113

24-
1. Fork 本仓库
25-
2. 新建 Feat_xxx 分支
26-
3. 提交代码
27-
4. 新建 Pull Request
114+
## 技术交流
28115

116+
- Q群:[707416319](https://qm.qq.com/cgi-bin/qm/qr?k=uSAXH8sKqQnF_cvDSF4T8IN7tSqabAJ3&jump_from=webapi)
29117

30-
#### 特技
118+
## 参考资料
31119

32-
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
33-
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
34-
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
35-
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
36-
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
37-
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
120+
- 官方资料
121+
- [GraalVM 入门](https://www.graalvm.org/docs/getting-started/)
122+
- [native-image 文档](https://www.graalvm.org/reference-manual/native-image/)
123+
- [JavaFX 中文官网](https://openjfx.cn/) `推荐阅读`
124+
- [Spring Native for GraalVM 文档](https://repo.spring.io/milestone/org/springframework/experimental/spring-graalvm-native-docs/0.8.5/spring-graalvm-native-docs-0.8.5.zip!/reference/index.html) `推荐阅读`
125+
- 网络文章
126+
- [如何评价 GraalVM 这个项目?](https://www.zhihu.com/question/274042223) `推荐阅读`
127+
- [GraalVM:微服务时代的Java](https://www.zhihu.com/column/p/137836206) `推荐阅读` `很全面的讲解`
128+
- [为 JavaFX 应用生成 native image](https://zhuanlan.zhihu.com/p/103606559?utm_source=wechat_session)
129+
- [Windows 下使用 GraalVM 将 JavaFX 应用编译成 exe](https://www.cnblogs.com/dehai/p/14258391.html)
130+
- [Spring Boot as GraalVM Native Images](https://blog.codecentric.de/en/2020/05/spring-boot-graalvm/) `推荐阅读` `可能需要“出国留学”工具`
131+
- [Spring Boot GraalVM Native Image builds with the native-image-maven-plugin](https://blog.codecentric.de/en/2020/05/spring-boot-graalvm/) `推荐阅读` `可能需要“出国留学”工具`

0 commit comments

Comments
 (0)