Grooy ã¹ã¯ãªããããã®ã¾ã¾æ¸¡ãã¦å®è¡ãã Spring Bootï¼Picocli ãã¼ã¹ã®ã³ãã³ãã©ã¤ã³ã¢ããªãä½æãã ( ãã®ï¼ï¼ )( GraalVM 㧠groovy-script-executor ã® Windows ç Native Image ãä½æãã )
æ¦è¦
è¨äºä¸è¦§ã¯ãã¡ãã§ãã
- ä»åã®æé ã§ç¢ºèªã§ããã®ã¯ä»¥ä¸ã®å
容ã§ãã
- GraalVM 㧠groovy-script-executor ã® Windows ç Native Image ãä½æãã¾ãã
åç §ãããµã¤ãã»æ¸ç±
-
Using GraalVM and Native Image on Windows 10
https://medium.com/graalvm/using-graalvm-and-native-image-on-windows-10-9954dc071311 Build Great Native CLI Apps in Java with Graalvm and Picocli
https://www.infoq.com/articles/java-native-cli-graalvm-picocli/2.3.2. Enabling the Annotation Processor
https://picocli.info/#_enabling_the_annotation_processorVisual Studio - ãã¦ã³ãã¼ã
https://visualstudio.microsoft.com/ja/downloads/GraalVM
https://www.graalvm.org/
ç®æ¬¡
- build.gradle ã«
annotationProcessor("info.picocli:picocli-codegen:${picocliVersion}")
ã追å ãã - Visual Studio 2022 Community ãã¤ã³ã¹ãã¼ã«ãã
- GraalVM Community 21.3.0 ãã¤ã³ã¹ãã¼ã«ãã
- groovy-script-executor ã® Windows ç Native Imageï¼gse.exeãgse-servlet.exeï¼ãä½æãã
- åä½ç¢ºèª
æé
build.gradle ã« annotationProcessor("info.picocli:picocli-codegen:${picocliVersion}")
ã追å ãã
https://picocli.info/#_enabling_the_annotation_processor ãåèã« build.gradle ã以ä¸ã®ããã«å¤æ´ãã¾ãã
.......... [compileJava, compileTestGroovy, compileTestJava]*.options*.encoding = "UTF-8" [compileJava, compileTestGroovy, compileTestJava]*.options*.compilerArgs = [ "-Xlint:all,-options,-processing,-path", "-Aproject=${project.group}/${project.name}" ] .......... dependencies { .......... def picocliVersion = "4.6.2" .......... // for Picocli implementation("info.picocli:picocli-spring-boot-starter:${picocliVersion}") annotationProcessor("info.picocli:picocli-codegen:${picocliVersion}") ..........
[compileJava, compileTestGroovy, compileTestJava]*.options*.compilerArgs
ã«"-Aproject=${project.group}/${project.name}"
ã追å ãã¾ãã- dependencies block ã«ä»¥ä¸ã®è¡ã追å ãã¾ãã
annotationProcessor("info.picocli:picocli-codegen:${picocliVersion}")
Gradle Tool Window ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ãã¦æ´æ°ãã¾ãã
clean ã¿ã¹ã¯å®è¡ â Rebuild Project å®è¡ â build ã¿ã¹ã¯ãå®è¡ãã¦çæããã build/libs/groovy-script-executor-1.0.0-RELEASE.jar ã D:\tmp ã«ã³ãã¼ãã¾ãã
Visual Studio 2022 Community ãã¤ã³ã¹ãã¼ã«ãã
Windows ç Native Image ãä½æããã®ã« Visual Studio 2022 Community ãå¿ è¦ãªã®ã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
ãã¦ã³ãã¼ã ãã¼ã¸ã®ãã³ãã¥ããã£ãã®ãç¡æãã¦ã³ãã¼ãããã¿ã³ãã¯ãªãã¯ã㦠vs_community__ï½.exeï¼ï½ ã®é¨åã«ã¯è±æ°åã®æååãå ¥ãã¾ãï¼ããã¦ã³ãã¼ããã¾ãã
vs_community__ï½.exe ãå®è¡ãã¦ã¤ã³ã¹ãã¼ã«ãã¾ãã以ä¸ã®ç»é¢ã表示ãããããåå¥ã®ã³ã³ãã¼ãã³ããã®ãMSVC v143 VS 2022 C++ x64/x86 ãã«ããã¼ã«(ææ°)ãããã§ãã¯ããå¾ãã¤ã³ã¹ãã¼ã«ããã¿ã³ãã¯ãªãã¯ãã¾ãã
ã¤ã³ã¹ãã¼ã«ãå®äºããã¨ãVisual Studio Installerãã«ãVisual Studio Community 2022ãã表示ããã¾ãã
GraalVM Community 21.3.0 ãã¤ã³ã¹ãã¼ã«ãã
https://www.graalvm.org/downloads/ ã®ãGraalVM Community 21.3.0ãã®ãDOWNLOAD FROM GITHUBããã¿ã³ãã¯ãªãã¯ãã㨠https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-21.3.0 ã¸é·ç§»ããã®ã§ããã®ä¸ã®ãJava 17 basedãã®ãWindows (amd64)ãã® link
ãã¯ãªãã¯ã㦠graalvm-ce-java17-windows-amd64-21.3.0.zip ããã¦ã³ãã¼ããã¾ãã
D:\graalvm ãã©ã«ããæ°è¦ä½æããå¾ãgraalvm-ce-java17-windows-amd64-21.3.0.zip ã解åãã¦ä½æããã graalvm-ce-java17-21.3.0 ãã©ã«ãããã®ä¸ã«ç§»åãã¾ãã
groovy-script-executor ã® Windows ç Native Imageï¼gse.exeãgse-servlet.exeï¼ãä½æãã
Windows ã¡ãã¥ã¼ãããVisual Studio 2022ã-ãx64 Native Tools Command Prompt for VS 2022ããã¯ãªãã¯ãã¦å®è¡ãã¾ãã
以ä¸ã®ã³ãã³ããå®è¡ã native-image ã³ãã³ãã使ç¨ã§ããããã«ãã¾ãã
> cd /d d:\tmp > set PATH=D:\graalvm\graalvm-ce-java17-21.3.0\bin;%PATH% > gu install native-image
以ä¸ã®ã³ãã³ããå®è¡ã gse.exe ãä½æãã¾ããgse.exe ã®å¾ã«æå®ãã¦ããã®ã¯ gse.bat å
ã«è¨è¿°ãã¦ããèµ·åæãªãã·ã§ã³ã§ãããã ã -XX:TieredStopAtLevel=1
ã¯æå®ã§ãã¾ããã§ããï¼ã¨ã©ã¼ã¡ãã»ã¼ã¸ãåºåãã㦠Native Image ã®çæã失æãã¾ãï¼ã
> native-image -jar groovy-script-executor-1.0.0-RELEASE.jar gse.exe -Dfile.encoding=UTF-8 -Dspring.main.lazy-initialization=true
以ä¸ã®ã³ãã³ããå®è¡ã gse-servlet.exe ãä½æãã¾ããgse-servlet.exe ã®å¾ã«æå®ãã¦ããã®ã¯ gse-servlet.bat å ã«è¨è¿°ãã¦ããèµ·åæãªãã·ã§ã³ã§ãã
> native-image -jar groovy-script-executor-1.0.0-RELEASE.jar gse-servlet.exe -Dfile.encoding=UTF-8 -Dspring.main.lazy-initialization=true -Dspring.main.web-application-type=servlet -Dlogging.level.root=INFO
åä½ç¢ºèª
ã¾ã㯠gse.exe ã®åä½ç¢ºèªãè¡ãã¾ãã
gse.exe Helloworld.groovy
ãå®è¡ãã㨠Hello, World
ã®æåãåºåããã¾ãããèµ·åå¾ã«ï¼ï½ï¼ç§ãããã®ã¯ Groovy ã¹ã¯ãªããã build ãã¦ããæéãªã®ã§ Native Image ã«ãã¦ãå¤ããã¾ããã§ããã
docker-compose up -d
ã§ã³ã³ãããèµ·åã㦠publications.csv ãåé¤ãã¦ãã gse.exe PublicationsTableToFileUsingUnivocityParsers.groovy
ãå®è¡ããã¨ã³ãã³ãã¯ã¨ã©ã¼ã¡ãã»ã¼ã¸ãåºåããã«çµäºãã
publications.csv ãçæããã¦ãã¼ã¿ãåºåããã¦ãã¾ããã
gse.exe SftpClient.groovy --user=user01 --password=pass01 --upload-dir=upload --upload-file=publications.csv
ã³ãã³ããå®è¡ããã¨ãã°ãåºåããã¦ã
upload ãã£ã¬ã¯ããªã« publications.csv ãã¢ãããã¼ãããã¾ããã
次㫠gse-servlet.exe ã®åä½ç¢ºèªãè¡ãã¾ãã
gse.exe StubServer.groovy
ãå®è¡ããã¨ä½ãåºåãããã«ã³ãã³ããçµäºãã¾ããã
gse-servlet.exe StubServer.groovy
ãå®è¡ããã¨ãã°ãåºåãã㦠Tomcat ãèµ·åãã
curl -v http://localhost:9080/stub
ãå®è¡ãã㨠{"key":123,"data":"xxxxxxxx"}
ãè¿ã£ã¦ãã¾ããã
gse.exeãgse-servlet.exe ã©ã¡ããåé¡ãªãããã§ãã
ã¾ãç°å¢å¤æ° PATH ãã JDKï¼D:\java\jdk-17.0.1.12-hotspot\bin
ï¼ã¸ã® PATH ãåé¤ãã¦ãã gse.exe Helloworld.groovy
ãå®è¡ãã¦ãã³ãã³ããå®è¡ããã¾ãããä½æããã Native Image 㯠JDK ããªãã¦ãåä½ãã¾ãï¼Groovy ã¹ã¯ãªããã® build ã«ã JDK ã¯å¿
è¦ãªãããã§ãï¼ã
å±¥æ´
2022/01/01
åççºè¡ã