BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Contribute

Topics

Choose your language

InfoQ Homepage News JHipster Native Blueprint Supports GraalVM Native Image

JHipster Native Blueprint Supports GraalVM Native Image

This item in japanese

Lire ce contenu en français

Bookmarks

The Spring Boot Native blueprint for JHipster generates code and configuration to create a JHipster project which uses Spring Native, an experimental Spring project that allows compiling Spring applications to native executables with the GraalVM Native Image compiler.

GraalVM native-images use ahead of time compilation to transform Java bytecode to a native image, which is a standalone executable. The resulting native image contains the application classes, dependency classes and even the necessary parts of the Substrate VM. A native image starts faster, is smaller and uses less memory compared to a traditional application running on a JVM. The downsides are slower builds and fewer runtime optimizations, because all configurations happens during build time.

GraalVM offers binaries for the various builds of the Community and Enterprise edition. After installing GraalVM Community the Native Image support may be added with the GraalVM Updater tool (gu):

gu install native-image

After this step, the Native Image executable will become available in the $JAVA_HOME/bin directory. The previously mentioned gu install native-image command will also install Native Image support from the GitHub catalog for GraalVM Community users. For GraalVM Enterprise users, manual installation is required.

Testing Native Image support is possible by creating a plain Java class, compiling the class with javac and creating a Native Image based on the compiled bytecode:

javac HelloWorld.java
native-image HelloWorld

The resulting Native Image contains the application, all libraries and the necessary JVM parts and can be run standalone:

./helloworld

The Spring Boot Native blueprint for JHipster generates code and configuration, to be used as a starting point before adding project-specific functionalities. The resulting project contains support for Spring Native which in turn uses the GraalVM native-image compiler to create executables for Spring applications.

JHipster requires a recent version of Node.js, after which, the JHipster and the JHipster Native blueprint may be installed:

npm install -g generator-jhipster
npm install -g generator-jhipster-native

A message is displayed when the installed Node.js version is too old for JHipster Native. Now a project directory may be created, however make sure the path doesn't contain spaces. Inside the project directory, the JHipster Native project may be generated:

jhipster-native

After configuring the project and adding the desired functionalities to the generated code, Maven may be used to create the native executable:

./mvnw package -Pnative,prod -DskipTests

Creating the executable requires some more time than a regular build as all the optimizations are performed ahead of time instead of during runtime. After the build completes successfully, the application may be run:

./target/native-executable

Initiated in 2019 by the Spring team which delivered the first beta version in March 2021, Spring Native is an experimental project to support native images for Spring applications.. The ideas and implementation of Spring Native are promoted to Spring 6.0 as announced during SpringOne 2021. The Spring Framework 6.0 roadmap shows that the GA release is scheduled for October 2022.

Developers can learn more in this blog post by Matt Raible, developer advocate at Okta, about running JHipster on GraalVM including instructions on configuring an identity provider.

About the Author

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT