|
1 | 1 | # java-graalvm-start
|
2 | 2 |
|
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). |
5 | 5 |
|
6 |
| -#### Software Architecture |
7 |
| -Software architecture description |
| 6 | +## Module overview |
8 | 7 |
|
9 |
| -#### Installation |
| 8 | +> The performance test results are related to the machine configuration, especially the time-consuming compilation of `native-image`. |
10 | 9 |
|
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) | |
14 | 20 |
|
15 |
| -#### Instructions |
| 21 | +## Development environment |
16 | 22 |
|
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). |
20 | 24 |
|
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 |
22 | 30 |
|
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) |
27 | 32 |
|
| 33 | +> Needless to say, System, IDE, and JDK, just skip... |
28 | 34 |
|
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 | +``` |
30 | 59 |
|
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-<A library that supports parsing args parameters> `For faster development of cli applications` |
| 110 | +- desktop-<Swing/AWT> `Other GUI implementations` |
| 111 | +- web-<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` |
0 commit comments