Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 17f

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide

In my previous article, I shared with you the steps I took, to set up a demo environment, so I could get started with Quarkus.
[https://technology.amis.nl/2020/08/17/quarkus-supersonic-subatomic-java-setting-up-a-demo-environment-using-vagrant-and-oracle-virtualbox]

In this article, you can read more about the steps I took to further automate setting up my demo environment and the Quarkus code guide “Quarkus – Creating Your First Application”, I tried out, including the hot deployment with background compilation.

As you may remember, the steps I took, to get started with Quarkus were:

  • Step 1 You need an IDE
    I installed IntelliJ IDEA Community Edition 2020.2 on my Windows laptop.

The next steps I installed on my demo environment with K3s (with the Kubernetes Dashboard) on top of an Ubuntu guest Operating System within an Oracle VirtualBox appliance:

  • Step 2a You need a JDK 8 or 11+ (any distribution)
    I installed AdoptOpenJDK 11 (LTS) HotSpot
  • Step 2b Optionally get GraalVM 20.1.0 for native compilation
    I installed GraalVM Community Edition 20.1.0
    I also installed the native-image tool (org.graalvm.native-image, version 20.1.0)
  • Step 3 You need Apache Maven 3.6.2+ or Gradle
    I installed Apache Maven 3.6.3
  • Step 4 Start Coding with Quarkus 1.7.0.Final
    This step didn’t need extra software to be installed.

Further automate setting up my demo environment

To further automate setting up my demo environment, I changed the content of Vagrantfile to:
[in bold, I highlighted the changes]

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  
  config.vm.define "ubuntu_k3s_quarkus" do |ubuntu_k3s_quarkus|
  
    config.vm.network "forwarded_port",
      guest: 8001,
      host:  8001,
      auto_correct: true
      
   config.vm.network "forwarded_port",
      guest: 8080,
      host:  8080,
      auto_correct: true
      
   config.vm.network "forwarded_port",
      guest: 8090,
      host:  8090,
      auto_correct: true
      
    config.vm.provider "virtualbox" do |vb|
        vb.name = "Ubuntu K3s Quarkus"
        vb.memory = "8192"
        vb.cpus = "1"
      
      args = []
      config.vm.provision "k3s shell script", type: "shell",
          path: "scripts/k3s.sh",
          args: args
          
      args = []
      config.vm.provision "helm shell script", type: "shell",
          path: "scripts/helm.sh",
          args: args
          
      args = []
      config.vm.provision "dashboard shell script", type: "shell",
          path: "scripts/dashboard.sh",
          args: args
          
      args = []
      config.vm.provision "quarkus shell script", type: "shell",
          path: "scripts/quarkus.sh",
          args: args
          
    end
    
  end

end

So, based on the manual steps mentioned in the previous article, in the scripts directory on my Windows laptop, I created the file quarkus.sh with the following content:

#!/bin/bash
echo "**** Begin installing Quarkus"

#Install AdoptOpenJDK
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
sudo apt-get update
sudo apt-get install -y adoptopenjdk-11-hotspot

#Install GraalVM
cd /tmp
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
sudo tar -xvf graalvm-ce-java11-linux-amd64-20.1.0.tar.gz -C /opt

cd /opt/graalvm-ce-java11-20.1.0/lib/installer/bin
sudo ./gu install native-image

#Install Maven
cd /tmp
wget http://apache.cs.uu.nl/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
sudo tar xzvf apache-maven-3.6.3-bin.tar.gz -C /opt

#Permanently setting environment variables for all users
sudo cp /vagrant/scripts/myenvvars.sh /etc/profile.d/myenvvars.sh

#Clean up
rm /tmp/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
rm /tmp/apache-maven-3.6.3-bin.tar.gz

echo "**** End installing Quarkus"

For permanently setting environment variables for all users, in the scripts directory I created the file myenvvars.sh with the following content:

export JAVA_HOME=/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64
export GRAALVM_HOME=/opt/graalvm-ce-java11-20.1.0/
export PATH=$JAVA_HOME/bin:${GRAALVM_HOME}/bin:/opt/apache-maven-3.6.3/bin:$PATH

From the subdirectory named env on my Windows laptop, I opened a Windows Command Prompt (cmd) and typed: vagrant up

This command creates and configures guest machines according to your Vagrantfile.
[https://www.vagrantup.com/docs/cli/up.html]

With the following output (only showing the part about Quarkus):

ubuntu_k3s_quarkus: **** Begin installing Quarkus
ubuntu_k3s_quarkus: Warning: apt-key output should not be parsed (stdout is not a terminal)
ubuntu_k3s_quarkus: OK
ubuntu_k3s_quarkus: Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
ubuntu_k3s_quarkus: Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
ubuntu_k3s_quarkus: Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
ubuntu_k3s_quarkus: Hit:4 https://download.docker.com/linux/ubuntu bionic InRelease
ubuntu_k3s_quarkus: Hit:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
ubuntu_k3s_quarkus: Get:6 https://adoptopenjdk.jfrog.io/adoptopenjdk/deb bionic InRelease [6155 B]
ubuntu_k3s_quarkus: Get:7 https://adoptopenjdk.jfrog.io/adoptopenjdk/deb bionic/main amd64 Packages [11.3 kB]

ubuntu_k3s_quarkus: update-alternatives:
ubuntu_k3s_quarkus: using /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode
ubuntu_k3s_quarkus: Processing triggers for systemd (237-3ubuntu10.42) …
ubuntu_k3s_quarkus: Processing triggers for man-db (2.8.3-2ubuntu0.1) …
ubuntu_k3s_quarkus: Processing triggers for ureadahead (0.100.0-21) …
ubuntu_k3s_quarkus: Processing triggers for libc-bin (2.27-3ubuntu1.2) …
ubuntu_k3s_quarkus: –2020-08-19 05:50:42– https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz

ubuntu_k3s_quarkus: Saving to: ‘graalvm-ce-java11-linux-amd64-20.1.0.tar.gz’
ubuntu_k3s_quarkus:
ubuntu_k3s_quarkus: 0K

ubuntu_k3s_quarkus: 2020-08-19 05:52:28 (4.04 MB/s) – ‘graalvm-ce-java11-linux-amd64-20.1.0.tar.gz’ saved [442680579/442680579]
ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/GRAALVM-README.md
ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/LICENSE.txt
ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/THIRD_PARTY_LICENSE.txt
ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/bin/gu
ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/bin/jvisualvm

ubuntu_k3s_quarkus: graalvm-ce-java11-20.1.0/lib/server/libjsig.so
ubuntu_k3s_quarkus: Downloading: Component catalog from www.graalvm.org
ubuntu_k3s_quarkus: Processing Component: Native Image
ubuntu_k3s_quarkus: Downloading: Component native-image: Native Image from github.com

ubuntu_k3s_quarkus: Installing new component: Native Image (org.graalvm.native-image, version 20.1.0)
ubuntu_k3s_quarkus: –2020-08-19 05:52:45– http://apache.cs.uu.nl/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
ubuntu_k3s_quarkus: Resolving apache.cs.uu.nl (apache.cs.uu.nl)…
ubuntu_k3s_quarkus: 131.211.31.189
ubuntu_k3s_quarkus: Connecting to apache.cs.uu.nl (apache.cs.uu.nl)|131.211.31.189|:80…
ubuntu_k3s_quarkus: connected.
ubuntu_k3s_quarkus: HTTP request sent, awaiting response…
ubuntu_k3s_quarkus: 200 OK
ubuntu_k3s_quarkus: Length:
ubuntu_k3s_quarkus: 9506321
ubuntu_k3s_quarkus: (9.1M)
ubuntu_k3s_quarkus: [application/x-gzip]
ubuntu_k3s_quarkus: Saving to: ‘apache-maven-3.6.3-bin.tar.gz’

ubuntu_k3s_quarkus: 2020-08-19 05:52:48 (3.42 MB/s) – ‘apache-maven-3.6.3-bin.tar.gz’ saved [9506321/9506321]

ubuntu_k3s_quarkus: apache-maven-3.6.3/lib/jansi-1.17.1.jar
ubuntu_k3s_quarkus: **** End installing Quarkus

I used vagrant ssh to connect into the running VM. Next, I used the following command on the Linux Command Prompt:

java --version

With the following output:

openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

In order to check the Maven version, I used the following command on the Linux Command Prompt:

mvn -v

With the following output:


Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 11.0.8, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64
Default locale: en, platform encoding: UTF-8
OS name: “linux”, version: “4.15.0-112-generic”, arch: “amd64”, family: “unix”

Step 4 Start Coding with Quarkus 1.7.0.Final

So, with all the software installation steps done, it was time to finally start coding with Quarkus.

On the “QUARKUS – GET STARTED” page, I clicked on the link “Start Coding” in step 4.
[https://www.graalvm.org/]

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 18

This page will help you bootstrap your Quarkus application and discover its extension ecosystem.

Think of Quarkus extensions as your project dependencies. Extensions configure, boot and integrate a framework or technology into your Quarkus application. They also do all of the heavy lifting of providing the right information to GraalVM for your application to compile natively.

Explore the wide breadth of technologies Quarkus applications can be made with. Generate your application!
[https://code.quarkus.io/]

This type of page looked familiar. In a previous article, for example, I used Spring Initializr to bootstrap an application.
[https://technology.amis.nl/2019/02/26/building-a-restful-web-service-with-spring-boot-using-an-h2-in-memory-database-and-also-an-external-mysql-database/]

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 19
[https://start.spring.io/]

In the “bootstrap your Quarkus application” page, I clicked on the link “CONFIGURE MORE OPTIONS” and left most as default and filled in:

• Group: nl.amis.demo.services
• Artifiact: aservice

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 20

Default, the Web extension “RESTEasy JAX-RS” is selected. This is the REST endpoint framework implementing JAX-RS and more. This will add the following dependency to the pom.xml as you will see later on:
[https://resteasy.github.io/]

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>

Remark:
With regard to REST services, as you can see, in the list of extension besides “RESTEasy JAX-RS” also the “RESTEasy JSON-B” extension (JSON-B serialization support for RESTEasy) can be selected. This will add the following dependency to the pom.xml:
[https://quarkus.io/guides/rest-json#creating-the-maven-project]
[http://json-b.net/]

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jsonb</artifactId>
    </dependency>

Quarkus also supports Jackson so, if you prefer Jackson over JSON-B, you can create a project relying on the “RESTEasy Jackson” extension (Jackson serialization support for RESTEasy) instead. This will add the following dependency to the pom.xml:
[https://quarkus.io/guides/rest-json#creating-the-maven-project]
[https://github.com/FasterXML/jackson]

<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jackson</artifactId>
    </dependency>

Then, on the “bootstrap your Quarkus application” page, I clicked the “Generate your application” button, followed by “Download as a zip” which downloaded a aservice.zip to my laptop.

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 21

I extracted the zip file in the applications directory on my Windows laptop.

Pom.xml

The pom.xml that is created, has the following content:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.amis.demo.services</groupId>
  <artifactId>aservice</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <properties>
    <compiler-plugin.version>3.8.1</compiler-plugin.version>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus-plugin.version>1.7.0.Final</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>1.7.0.Final</quarkus.platform.version>
    <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare</goal>
              <goal>prepare-tests</goal>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</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>
</project>

Importing the project into IntelliJ IDEA

Within IntelliJ IDEA, I imported the project and selected directory: C:\My\AMIS\env\applications\aservice. Next, I chose “Import project from external model: Maven” and kept the rest as default.

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 22

In order to check the directory content, I used the following command on the Linux Command Prompt:

cd /vagrant/applications/aservice
ls -latr

With the following output:


total 65
drwxrwxrwx 1 vagrant vagrant     0 Aug 18 19:26 src
-rwxrwxrwx 1 vagrant vagrant  4168 Aug 18 19:26 pom.xml
-rwxrwxrwx 1 vagrant vagrant  6607 Aug 18 19:26 mvnw.cmd
-rwxrwxrwx 1 vagrant vagrant 10069 Aug 18 19:26 mvnw
-rwxrwxrwx 1 vagrant vagrant  1192 Aug 18 19:26 README.md
drwxrwxrwx 1 vagrant vagrant     0 Aug 18 19:26 .mvn
-rwxrwxrwx 1 vagrant vagrant   308 Aug 18 19:26 .gitignore
-rwxrwxrwx 1 vagrant vagrant    75 Aug 18 19:26 .dockerignore
drwxrwxrwx 1 vagrant vagrant  4096 Aug 19 19:38 ..
-rwxrwxrwx 1 vagrant vagrant 17860 Aug 19 19:42 aservice.iml
drwxrwxrwx 1 vagrant vagrant  4096 Aug 19 19:42 .
drwxrwxrwx 1 vagrant vagrant  4096 Aug 19 19:42 .idea

In order to compile the code, I used the following command on the Linux Command Prompt:

./mvnw compile quarkus:dev

With the following output:


[INFO] Scanning for projects…
Downloading from central: https://repo.maven.apache.org/maven2/io/quarkus/quarkus-universe-bom/1.7.0.Final/quarkus-universe-bom-1.7.0.Final.pom

[INFO] Changes detected – recompiling the module!
[INFO] Compiling 1 source file to /vagrant/applications/aservice/target/classes
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:dev (default-cli) @ aservice —
Listening for transport dt_socket at address: 5005
__  ____  __  _____   ___  __ ____  ______
 –/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
–\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2020-08-19 19:50:03,746 INFO  [io.quarkus] (Quarkus Main Thread) aservice 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.7.0.Final) started in 6.674s. Listening on: http://0.0.0.0:8080
2020-08-19 19:50:03,762 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2020-08-19 19:50:03,763 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy]

Then, in the Web Browser on my Windows laptop, I entered the URL: http://localhost:8080/hello

And I got the following result:

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 23

Remark:
Remember that on my Windows laptop, I could call port 8080 of my guest operating system because via port forwarding this was made possible.

Next, I wanted to try out some of the code guides.

Be Guided Through First Application

On the “QUARKUS – GET STARTED” page, I clicked on the link “Be Guided Through First Application”.
[https://quarkus.io/guides/getting-started]

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 24

In this guide, we create a straightforward application serving a hello endpoint. To demonstrate dependency injection, this endpoint uses a greeting bean.

This guide also covers the testing of the endpoint.
[https://quarkus.io/guides/getting-started]

I will leave it up to you to follow this guide also. I will only share with you some of the steps.

In order to create a new Quarkus project, I used the following command on the Linux Command Prompt:

cd /vagrant/applications
mvn io.quarkus:quarkus-maven-plugin:1.7.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=getting-started \
    -DclassName="org.acme.getting.started.GreetingResource" \
    -Dpath="/hello"
cd getting-started

With the following output:


[INFO] Scanning for projects…
[INFO]
[INFO] ——————< org.apache.maven:standalone-pom >——————-
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ——————————–[ pom ]———————————
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:create (default-cli) @ standalone-pom —
Downloading from central: https://repo.maven.apache.org/maven2/io/quarkus/quarkus-universe-bom/maven-metadata.xml

Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.5/antlr4-runtime-4.5.jar (374 kB at 94 kB/s)
[INFO]
[INFO] Maven Wrapper version 0.5.6 has been successfully set up for your project.
[INFO] Using Apache Maven: 3.6.3
[INFO] Repo URL in properties file: https://repo.maven.apache.org/maven2
[INFO]
[INFO]
[INFO] ========================================================================================
[INFO] Your new application has been created in /vagrant/applications/getting-started
[INFO] Navigate into this directory and launch your application with mvn quarkus:dev
[INFO] Your application will be accessible on http://localhost:8080
[INFO] ========================================================================================
[INFO]
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time:  25.961 s
[INFO] Finished at: 2020-08-20T16:58:23Z
[INFO] ————————————————————————
vagrant@ubuntu-bionic:/vagrant/applications$ cd getting-started
vagrant@ubuntu-bionic:/vagrant/applications/getting-started$

So, this is another way to create a Quarkus project instead of using the “bootstrap your Quarkus application” page.

Pom.xml

The pom.xml that is created, has the following content:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.acme</groupId>
  <artifactId>getting-started</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <compiler-plugin.version>3.8.1</compiler-plugin.version>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus-plugin.version>1.7.0.Final</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>1.7.0.Final</quarkus.platform.version>
    <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare</goal>
              <goal>prepare-tests</goal>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</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>
</project>

Remark:
You will find the import of the Quarkus BOM, allowing you to omit the version on the different Quarkus dependencies. In addition, you can see the quarkus-maven-plugin responsible of the packaging of the application and also providing the development mode.
[ https://quarkus.io/guides/getting-started#bootstrapping-the-project]

As mentioned before with regard to the dependencies, the quarkus-resteasy dependency (the REST endpoint framework implementing JAX-RS and more) is used.

With regard to testing you can see 2 test dependencies are used, quarkus-junit5 and rest-assured.

quarkus-junit5 is required for testing, as it provides the @QuarkusTest annotation that controls the testing framework. rest-assured is not required but is a convenient way to test HTTP endpoints, we also provide integration that automatically sets the correct URL so no configuration is required.
[https://quarkus.io/guides/getting-started-testing]

Quarkus supports Junit 5 tests. Because of this, the version of the Surefire Maven Plugin must be set, as the default version does not support Junit 5.
[https://quarkus.io/guides/getting-started]

For more information about this and the content of the pom.xml please see the Quarkus documentation.
[https://quarkus.io/support/]

Importing the project into IntelliJ IDEA

Within IntelliJ IDEA, I imported the project (in the same way as before) by selecting directory: C:\My\AMIS\env\applications\getting-started.

Then I followed the guide and made changes to the generated code.

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 25

I also added a custom banner as mentioned in the guide.
Users can supply a custom banner by placing the banner file in src/main/resources and configuring quarkus.banner.path=name-of-file in application.properties.
[https://quarkus.io/guides/getting-started#banner]

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 26

In order to compile the code, (as before) I used the following command on the Linux Command Prompt:

./mvnw compile quarkus:dev

With the following output:

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 27

Remark:
quarkus:dev runs Quarkus in development mode. This enables hot deployment with background compilation, which means that when you modify your Java files and/or your resource files and refresh your browser, these changes will automatically take effect. This works too for resource files like the configuration property file. Refreshing the browser triggers a scan of the workspace, and if any changes are detected, the Java files are recompiled and the application is redeployed; your request is then serviced by the redeployed application. If there are any issues with compilation or deployment an error page will let you know.

This will also listen for a debugger on port 5005. If you want to wait for the debugger to attach before running you can pass -Dsuspend on the command line. If you don’t want the debugger at all you can use -Ddebug=false.
[https://quarkus.io/guides/getting-started#development-mode]

Then, in the Web Browser on my Windows laptop, I entered the URL: http://localhost:8080/greeting/quarkus

And I got the following result:

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 28

Hot deployment with background compilation

So, with Quarkus running in development mode, I wanted to try out the hot deployment with background compilation and therefor I changed the code of the greeting method to the following:
[in bold, I highlighted the changes]

@ApplicationScoped
public class GreetingService {

    public String greeting(String name) {
        return "hello " + name + ", a warm welcome from AMIS";
    }

}

Then, in the Web Browser on my Windows laptop, I refreshed the page with URL: http://localhost:8080/greeting/quarkus

Using Vagrant and shell scripts to further automate setting up my Quarkus demo environment from scratch and trying out a Quarkus code guide lameriks 2020 08 29

As you can see, the changes automatically took effect.
I then reverted this change, in order for the unit test to pass.

Testing the Quarkus project

In order to test the Quarkus project, I used the following command on the Linux Command Prompt:

./mvnw test

With the following output:

[INFO] Scanning for projects…
[INFO]
[INFO] ———————-< org.acme:getting-started >———————-
[INFO] Building getting-started 1.0-SNAPSHOT
[INFO] ——————————–[ jar ]———————————
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:prepare (default) @ getting-started —
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ getting-started —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.1:compile (default-compile) @ getting-started —
[INFO] Nothing to compile – all classes are up to date
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:prepare-tests (default) @ getting-started —
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ getting-started —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /vagrant/applications/getting-started/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ getting-started —
[INFO] Nothing to compile – all classes are up to date
[INFO]
[INFO] — maven-surefire-plugin:3.0.0-M5:test (default-test) @ getting-started —
[INFO]
[INFO] ——————————————————-
[INFO] T E S T S
[INFO] ——————————————————-
[INFO] Running org.acme.getting.started.GreetingResourceTest
2020-08-20 17:52:11,030 INFO [io.quarkus] (main) Quarkus 1.7.0.Final on JVM started in 11.711s. Listening on: http://0.0.0.0:8081
2020-08-20 17:52:11,241 INFO [io.quarkus] (main) Profile test activated.
2020-08-20 17:52:11,243 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23.173 s – in org.acme.getting.started.GreetingResourceTest
2020-08-20 17:52:20,297 INFO [io.quarkus] (main) Quarkus stopped in 0.101s
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 47.032 s
[INFO] Finished at: 2020-08-20T17:52:21Z
[INFO] ————————————————————————
vagrant@ubuntu-bionic:/vagrant/applications/getting-started$

Remark:
By default, tests will run on port 8081 so as not to conflict with the running application. Quarkus automatically configures RestAssured to use this port.
[https://quarkus.io/guides/getting-started#testing]

Packaging the Quarkus project

In order to package the Quarkus project, I used the following command on the Linux Command Prompt:

./mvnw package

With the following output:


[INFO] Scanning for projects…
[INFO]
[INFO] ———————-< org.acme:getting-started >———————-
[INFO] Building getting-started 1.0-SNAPSHOT
[INFO] ——————————–[ jar ]———————————
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:prepare (default) @ getting-started —
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ getting-started —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.1:compile (default-compile) @ getting-started —
[INFO] Nothing to compile – all classes are up to date
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:prepare-tests (default) @ getting-started —
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ getting-started —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /vagrant/applications/getting-started/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ getting-started —
[INFO] Nothing to compile – all classes are up to date
[INFO]
[INFO] — maven-surefire-plugin:3.0.0-M5:test (default-test) @ getting-started —
[INFO]
[INFO] ——————————————————-
[INFO]  T E S T S
[INFO] ——————————————————-
[INFO] Running org.acme.getting.started.GreetingResourceTest
2020-08-20 18:01:38,133 INFO  [io.quarkus] (main) Quarkus 1.7.0.Final on JVM started in 12.317s. Listening on: http://0.0.0.0:8081
2020-08-20 18:01:38,333 INFO  [io.quarkus] (main) Profile test activated.
2020-08-20 18:01:38,334 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23.838 s – in org.acme.getting.started.GreetingResourceTest
2020-08-20 18:01:47,622 INFO  [io.quarkus] (main) Quarkus stopped in 0.117s
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] — maven-jar-plugin:2.4:jar (default-jar) @ getting-started —
[INFO]
[INFO] — quarkus-maven-plugin:1.7.0.Final:build (default) @ getting-started —
[INFO] [org.jboss.threads] JBoss Threads version 3.1.1.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building thin jar: /vagrant/applications/getting-started/target/getting-started-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 12083ms
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time:  01:02 min
[INFO] Finished at: 2020-08-20T18:02:02Z
[INFO] ————————————————————————
vagrant@ubuntu-bionic:/vagrant/applications/getting-started$

Remark:
It produces 2 jar files in /target:

You can run the application using: java -jar target/getting-started-1.0-SNAPSHOT-runner.jar
[https://quarkus.io/guides/getting-started#packaging-and-run-the-application]

So now I conclude this article. I shared with you the steps I took to further automate setting up my demo environment and the Quarkus code guide “Quarkus – Creating Your First Application” I tried out, including the hot deployment with background compilation.

In a next article, you can read more about other Quarkus code guides I tried out, related to the following topics:

  • Compiling the application to a native executable
  • Packaging the native executable in a container
  • The ability to automatically generate Kubernetes resources by Quarkus