<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Spring Native 入門實戰(zhàn)

          共 3510字,需瀏覽 8分鐘

           ·

          2021-04-02 23:26

          基礎(chǔ)環(huán)境說明

          GraalVM 是一種高性能的虛擬機,它可以顯著的提高程序的性能和運行效率,非常適合微服務。

          0dc8355e2e7a78ab02276dab2133e3b4.webp

          下載地址如下,和普通 JDK 安裝一致:

          • Linux (amd64) - link[1]
          • Linux (aarch64) - link[2]
          • MacOS (amd64) ? - link[3]
          • Windows (amd64) - link[4]

          PS: 如果使用 MacOS Catalina 及更新版本,請在安裝之前執(zhí)行以下命令,不然會提示文件已損壞。

          sudo?xattr?-r?-d?com.apple.quarantine?path/to/graalvm/folder/

          上手 Spring Native

          • 基于https://start.spring.io[5] 創(chuàng)建項目
          b69a15f87bb3b33ced33ef1e6ad73222.webpmaven 依賴
          • 添加 native-image 構(gòu)建 profile
          ?<profiles>
          ??<profile>
          ???<id>native-image</id>
          ???<build>
          ????<plugins>
          ?????<plugin>
          ??????<groupId>org.graalvm.nativeimage</groupId>
          ??????<artifactId>native-image-maven-plugin</artifactId>
          ??????<version>21.0.0</version>
          ??????<configuration>
          ??????????????<!--?這里要指定?Main?方法的入口?-->
          ???????<mainClass>com.example.demo.DemoApplication</mainClass>
          ??????</configuration>
          ??????<executions>
          ???????<execution>
          ????????<goals>
          ?????????<goal>native-image</goal>
          ????????</goals>
          ????????<phase>package</phase>
          ???????</execution>
          ??????</executions>
          ?????</plugin>
          ????</plugins>
          ???</build>
          ??</profile>
          ?</profiles>

          • 指定原有的 spring-boot-maven-plugin 構(gòu)建出 exec 程序
          <plugin>
          ??<groupId>org.springframework.boot</groupId>
          ??<artifactId>spring-boot-maven-plugin</artifactId>
          ??<configuration>
          ????<!--執(zhí)行classifier為exec-->
          ????<classifier>exec</classifier>
          ????<image>
          ??????<builder>paketobuildpacks/builder:tiny</builder>
          ??????<env>
          ????????<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
          ??????</env>
          ????</image>
          ??</configuration>
          </plugin>

          開始構(gòu)建

          • 執(zhí)行 mvn 命令
          ?mvn?-Pnative-image?package
          • 構(gòu)建成功, 耗時三分鐘。
          [INFO]?BUILD?SUCCESS
          [INFO]?------------------------------------------------------------------------
          [INFO]?Total?time:?03:03?min
          [INFO]?Finished?at:?2021-03-28T12:17:55+08:00
          [INFO]?Final?Memory:?113M/310M
          [INFO]?------------------------------------------------------------------------

          ls?-lh?target/com.example.demo.demoapplication
          -rwxr-xr-x??1?lengleng??staff????57M?Mar?28?12:17?target/com.example.demo.demoapplication
          • 運行測試
          target/com.example.demo.demoapplication

          使用 upx 繼續(xù)壓縮

          UPX - the Ultimate Packer for eXecutables 是一款開源的可執(zhí)行文件壓縮程序,可以壓縮常見平臺下的可執(zhí)行程序包。

          • 安裝并壓縮 native-image 生成的執(zhí)行文件
          brew?install?upx
          upx?com.example.demo.demoapplication
          • 壓縮為原來的 30% ,且能夠正常運行。
          ???????????????????????Ultimate?Packer?for?eXecutables
          ??????????????????????????Copyright?(C)?1996?-?2020
          UPX?3.96????????Markus?Oberhumer,?Laszlo?Molnar?&?John?Reiser???Jan?23rd?2020

          ????????File?size?????????Ratio??????Format??????Name
          ???--------------------???------???-----------???-----------
          ??60185112?->??18501648???30.74%???macho/amd64???com.example.demo.demoapplication

          Packed?1?file.
          ls?-lh?target/com.example.demo.demoapplication
          -rwxr-xr-x??1?lengleng??staff????18M?Mar?28?12:17?target/com.example.demo.demoapplication

          參考資料

          [1]

          link: https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-linux-amd64-21.0.0.2.tar.gz

          [2]

          link: https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-linux-aarch64-21.0.0.2.tar.gz

          [3]

          link: https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-darwin-amd64-21.0.0.2.tar.gz

          [4]

          link: https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-windows-amd64-21.0.0.2.zip

          [5]

          https://start.spring.io: https://start.spring.io


          瀏覽 136
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  在线观看黄色一级电影及小说 | 亚洲日韩欧美三级片 | 激情国产综合 | 天堂AV中文在线 | 一级黄片99日日 |