preface

Quarkus framework is a Kurbernetes Native Java framework designed for GraalVM and OpenJDK HotSpot.

Install graalvm

Download: GraalVM official website

Note that the 2.71Final version I selected here requires a more recent version of Maven. I chose Apache Maven 3.8.4

Configuring environment Variables

Set the GRAALVM_HOME and JAVA_HOME environment variables to the root of GraalVM, where the configuration can be adjusted by command to facilitate programming

Export JAVA_11_HOME = / Library/Java/JavaVirtualMachines/JDK - 11.0.14. JDK/Contents/Home export JAVA_8_HOME = / Library/Java/JavaVirtualMachines jdk1.8.0 _261. JDK/Contents/Home export GRAALVM_HOME=/ XXX /Documents/graalvm-ce-java11-21.3.0/Contents/Home # default JDK1.7 export JAVA_HOME=$JAVA_8_HOME #alias Dynamically switch the JDK version and path address alias jdk11="export JAVA_HOME=$JAVA_11_HOME" alias jdk8="export JAVA_HOME=$JAVA_8_HOME" alias gra11="export JAVA_HOME=$GRAALVM_HOME" alias Grapath = PATH = / XXX/Documents/graalvm - ce - java11-21.3.0 / Contents/Home/bin: $PATHCopy the code

After installing the command, you can check whether the system configuration is successful:

$ gu -list

$ java -version

Install the native – image

Use the GU command to download the native image module

$ gu install native-image`
Downloading: Component catalog from www.graalvm.org
Processing Component: Native Image
Downloading: Component native-image: Native Image  from github.com
Installing new component: Native Image
Copy the code

Initialize the Quarkus framework

One way is to initialize the project in code.quarkus. IO /. After initialization, you can directly download the ZIP package to open it.

There is also a way to configure Maven manually

The < < the groupId > org/groupId > < artifactId > org. Test < / artifactId > < version > 1.0 - the SNAPSHOT < / version > < properties > < quarkus version > 2.7.1. Final < / quarkus version > < maven. Home > / Users/xuejiameng/Documents/maven/apache maven - 3.8.4 < / maven. Home > <surefire plugin. Version > </surefire plugin. Version > </properties> <dependencyManagement> <dependencies> <! Quarkus </groupId> <artifactId> Quarkus </artifactId> <version>${quarkus.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <! Quarkus </groupId> <artifactId>quarkus </artifactId> </dependency> <! -- Junit --> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-junit5</artifactId> <scope>test</scope> </dependency> <! Rest assured</groupId> <artifactId> Rest assured</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <! Maven plugin --> <plugin> <groupId> IO. Quarkus </groupId> <version>${quarkus.version}</version> <executions> <execution> <goals> <goal>build</goal> </goals> </execution> </executions> </plugin> <! Maven-surefire-plugin </artifactId> <version>${surefire-plugin.version}</version> <configuration> <systemProperties> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> </systemProperties> </configuration> </plugin> </plugins> </build>Copy the code

Once configured, you can write a simple Hello program to test it

@Path("/hello") public class GreetingResource { @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return "hello"; }}Copy the code

Enter commands in the folder$ mvn quarkus:devYou can see the results of the run

Native – image packaging

We have just installed the native image module in GU, now we can try to use the native Image packaging program to add the configuration in POM first

<profiles> <profile> <id>native</id> <activation> <property> <name>native</name> </property> </activation> <build> Maven-failsafe-plugin </artifactId> <version> 3.0.6-m3 </version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <systemPropertyVariables> <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <maven.home>${maven.home}</maven.home> </systemPropertyVariables> </configuration> </execution> </executions> </plugin> </plugins> </build> <properties> <quarkus.package.type>native</quarkus.package.type> </properties> </profile> </profiles>Copy the code

After the installation package is complete, enter the command $MVN package-pnative in the folder:

/org. test-1.0-snapshot-runner = /org. test-1.0-snapshot-runner = /org. test-1.0-snapshot-runner = /org. test-1.0-snapshot-runner = /org. test-1.0-snapshot-runner

The result is the same.

conclusion

One of the biggest advantages of Quarkus apps is that Pnative is built to start up much faster than frameworks like Spring, which can be hundreds of times faster, as well as graalVM and its corresponding support for container and cloud native.