Chapter 1. Developing and compiling your Quarkus applications with Apache Maven
As an application developer, you can use Red Hat build of Quarkus to create microservices-based applications written in Java that run on OpenShift and serverless environments. Applications compiled to native executables have small memory footprints and fast startup times.
This guide describes how to create a Quarkus project using the Apache Maven plug-in.
Prerequisites
Have OpenJDK (JDK) 11 installed and the
JAVA_HOMEenvironment variable set to specify the location of the Java SDK.- Log in to the Red Hat Customer Portal to download Red Hat build of Open JDK from the Software Downloads page.
Apache Maven 3.8.1 or higher is installed.
- Download Maven from the Apache Maven Project website.
1.1. Red Hat build of Quarkus リンクのコピーリンクがクリップボードにコピーされました!
Red Hat build of Quarkus is a Kubernetes-native Java stack that is optimized for use with containers and Red Hat OpenShift Container Platform. Quarkus is designed to work with popular Java standards, frameworks, and libraries such as Eclipse MicroProfile, Apache Kafka, RESTEasy (JAX-RS), Hibernate ORM (JPA), Spring, Infinispan, and Apache Camel.
The Quarkus dependency injection solution is based on CDI (contexts and dependency injection) and includes an extension framework to expand functionality and to configure, boot, and integrate a framework into your application. Dependency injection in the Red Hat build of Quarkus is based on Quarkus ArC, a CDI-based build-time-oriented dependency injection solution for Quarkus architecture. ArC is a transitive quarkus-resteasy dependency, and as such, it is already present in your project.
Quarkus provides a container-first approach to building Java applications. This approach makes it much easier to build microservices-based applications written in Java as well as enabling those applications to invoke functions running on serverless computing frameworks. For this reason, Quarkus applications have small memory footprints and fast startup times.
1.2. Apache Maven and Quarkus リンクのコピーリンクがクリップボードにコピーされました!
Apache Maven is a distributed build automation tool used in Java application development to create, manage, and build software projects. Maven uses standard configuration files called Project Object Model (POM) files to define projects and manage the build process. POM files describe the module and component dependencies, build order, and targets for the resulting project packaging and output using an XML file. This ensures that the project is built in a correct and uniform manner.
Maven repositories
A Maven repository stores Java libraries, plug-ins, and other build artifacts. The default public repository is the Maven 2 Central Repository, but repositories can be private and internal within a company to share common artifacts among development teams. Repositories are also available from third-parties.
You can use Red Hat’s hosted online Maven repository with your Quarkus projects or you can download the Red Hat build of Quarkus Maven repository.
Maven plug-ins
Maven plug-ins are defined parts of a POM file that achieve one or more goals. Quarkus applications use the following Maven plug-ins:
-
Quarkus Maven plug-in (
quarkus-maven-plugin): Enables Maven to create Quarkus projects, packages your applications as JAR files, and provides a development mode. -
Maven Surefire plug-in (
maven-surefire-plugin): When Quarkus enables thetestprofile, the Maven Surefire plug-in is used during thetestphase of the build life cycle to execute unit tests on your application. The plug-in generates text and XML files that contain the test reports.
1.2.1. Configuring the Maven settings.xml file for the online repository リンクのコピーリンクがクリップボードにコピーされました!
You can use the Red Hat’s hosted online Quarkus repository with your Quarkus Maven project by configuring your user settings.xml file. This is the recommended approach. Maven settings used with a repository manager or repository on a shared server provide better control and manageability of projects.
When you configure the repository by modifying the Maven settings.xml file, the changes apply to all of your Maven projects.
Procedure
Open the Maven
~/.m2/settings.xmlfile in a text editor or integrated development environment (IDE).NoteIf there is not a
settings.xmlfile in the~/.m2/directory, copy thesettings.xmlfile from the$MAVEN_HOME/.m2/conf/directory into the~/.m2/directory.Add the following lines to the
<profiles>element of thesettings.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following lines to the
<activeProfiles>element of thesettings.xmlfile and save the file.<activeProfile>red-hat-enterprise-maven-repository</activeProfile>
<activeProfile>red-hat-enterprise-maven-repository</activeProfile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.2.2. Downloading and configuring the Quarkus Maven repository リンクのコピーリンクがクリップボードにコピーされました!
If you do not want to use the online Maven repository, you can download and configure the Quarkus Maven repository to create a Quarkus application with Maven. The Quarkus Maven repository contains many of the dependencies that Java developers typically use to build their applications. This procedure describes how to edit the settings.xml file to configure the Quarkus Maven repository.
When you configure the repository by modifying the Maven settings.xml file, the changes apply to all of your Maven projects.
Procedure
- Download the Quarkus Maven repository ZIP file from the Software Downloads page of the Red Hat Customer Portal (login required).
- Extract the downloaded archive.
-
Change directory to the
~/.m2/directory and open the Mavensettings.xmlfile in a text editor or integrated development environment (IDE). Add the path of the Quarkus Maven repository that you downloaded to the
<profiles>element of thesettings.xmlfile. The format of the path of the Quarkus Maven repository must befile://$PATH, for examplefile:///home/userX/rh-quarkus-2.2.5.GA-maven-repository/maven-repository.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following lines to the
<activeProfiles>element of thesettings.xmlfile and save the file.<activeProfile>red-hat-enterprise-maven-repository</activeProfile>
<activeProfile>red-hat-enterprise-maven-repository</activeProfile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If your Maven repository contains outdated artifacts, you might encounter one of the following Maven error messages when you build or deploy your project, where <artifact_name> is the name of a missing artifact and <project_name> is the name of the project you are trying to build:
-
Missing artifact <project_name> -
[ERROR] Failed to execute goal on project <artifact_name>; Could not resolve dependencies for <project_name>
To resolve the issue, delete the cached version of your local repository located in the ~/.m2/repository directory to force a download of the latest Maven artifacts.
1.3. Creating a Quarkus project on the command line リンクのコピーリンクがクリップボードにコピーされました!
You can use the Quarkus Maven plug-in on the command line to create a Quarkus project by providing attributes and values on the command line or by using the plug-in in interactive mode. The resulting project will contain the following elements:
- The Maven structure
- An associated unit test
-
A landing page that is accessible on
http://localhost:8080after you start the application -
Example
Dockerfilefiles for JVM and native mode insrc/main/docker - The application configuration file
Procedure
In a command terminal, enter the following command to verify that Maven is using JDK 11 or 17, and that the Maven version is 3.8.1 or higher:
mvn --version
mvn --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow - If the preceding command does not return JDK 11 or 17, add the path to JDK 11 to the PATH environment variable and enter the preceding command again.
To use the Quarkus Maven plug-in to create a new project, use one of the following methods:
Enter the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this command, replace the following values:
-
<project_group_id>: A unique identifier of your project -
<project_artifact_id>: The name of your project and your project directory
-
Create the project in interactive mode:
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:2.2.5.Final-redhat-00007:create
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:2.2.5.Final-redhat-00007:createCopy to Clipboard Copied! Toggle word wrap Toggle overflow When prompted, enter the required attribute values.
NoteAlternatively, you can create your project using the default values for the project attributes by entering the following command:
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:2.2.5.Final-redhat-00007:create -BThe following table lists the attributes that you can define with the
createcommand:Expand Attribute Default Value Description projectGroupIdorg.acmeA unique identifier of your project.
projectArtifactIdnone
The name of your project and your project directory. If you do not specify the
projectArtifactId, the Maven plug-in starts the interactive mode. If the directory already exists, the generation fails.projectVersion1.0-SNAPSHOTThe version of your project.
platformGroupIdcom.redhat.quarkus.platformThe group id of your platform. All the existing platforms are provided by
io.quarkus. However, you can change the default value.platformArtifactIdquarkus-bomThe artifact id of your platform BOM. To use the locally built Quarkus add
quarkus-bomto yourpom.xmlfile.platformVersionThe latest platform version
The version of the platform you want to use for your project. You can provide a version range and the Maven plug-in uses the latest version.
className${projectGroupId}/GreetingResource.java
The fully qualified name of the generated resource. After the application is created, the REST endpoint is exposed at the following URL:
http://localhost:8080/$pathIf you use the default
path, the URL ishttp://localhost:8080/hello.path/helloThe resource path, only if you set the
className.extensions[]
The list of extensions you want to add to your project, separated by a comma.
By default, the Quarkus Maven plug-in uses the latest quarkus-bom file. This BOM aggregates extensions so you can reference them from your applications to align the dependency versions. If you are offline, the Quarkus Maven plug-in uses the latest locally available version of the quarkus-bom. If Maven finds the quarkus-bom version 2.0 or earlier, it will use the platform based on the quarkus-bom.
1.4. Creating a Quarkus project by configuring the pom.xml file リンクのコピーリンクがクリップボードにコピーされました!
You can create a Quarkus project by configuring the Maven POM XML file.
Procedure
-
Open the
pom.xmlfile in a text editor. Add the configuration properties that contain:
- the version of the Quarkus Maven plugin
-
the
groupID,artifactIDandversionof the Quarkus BOM - the version of the Maven Surefire plugin
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the Quarkus GAV (group, artifact, version) and use the
quarkus-bomfile to omit the versions of the different Quarkus dependencies:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the Quarkus Maven plug-in:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe maven-surefire-plugin runs the unit tests for your application.
Optional: To build a native application, add a specific native profile that includes the Maven Failsafe plug-in:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Tests that include
ITin their names and contain the@NativeImageTestannotation are run against the native executable. - For the complete explanation about native applications and their difference from JVM applications, see the Difference between JVM and native mode chapter.
-
Tests that include
1.5. Creating a Quarkus Maven project using code.quarkus.redhat.com リンクのコピーリンクがクリップボードにコピーされました!
As an application developer, you can use code.quarkus.redhat.com to generate a Quarkus Maven project and automatically add and configure the extensions that you want to use in your application. In addition, code.quarkus.redhat.com automatically manages the configuration parameters required to compile your project into a native executable.
This section walks you through the process of generating a Quarkus Maven project, including:
- Specifying basic details about your application.
- Choosing the extensions that you want to include in your project.
- Generating a downloadable archive with your project files.
- Using the custom commands for compiling and starting your application.
Prerequisites
- Have a web browser.
Procedure
- Navigate to https://code.quarkus.redhat.com using a web browser.
Specify basic details about your project:
-
Enter a group name for your project. The name format follows the Java package naming convention, for example,
org.acme. -
Enter a name that you want to use for Maven artifacts generated from your project, for example,
code-with-quarkus. Select the build tool you want to use to compile and start your application. The build tool that you choose determines:
- the directory structure of your generated project
- the format of configuration files used in your generated project
the custom build script and command for compiling and starting your application that code.quarkus.redhat.com displays for you after you generate your project
NoteRed Hat provides support for using code.quarkus.redhat.com to create Quarkus Maven projects only.
-
Enter a group name for your project. The name format follows the Java package naming convention, for example,
Specify additional details about your application project:
- Select Configure more options to display the fields that contain further application details.
-
Enter a version that is used in artifacts generated from your project. The default value of this field is
1.0.0-SNAPSHOT. Using semantic versioning is recommended, but you can use a different type of versioning if you prefer. Select whether you want code.quarkus.redhat.com to add starter code to your project. When you add extensions that are marked with CODE to your project from the list of extensions, you can enable this option to automatically create example class files and resource files for those extensions when you generate your project. This option does not affect your generated project when you do not add any extensions that provide an example code.
Notecode.quarkus.redhat.com automatically uses the latest release of Red Hat build of Quarkus. You can manually change the BOM version in the
pom.xmlfile after you generate your project.
Select the extensions you want to use in your application from the list of extensions. The selected extensions are included as dependencies of your Quarkus application, with their versions being managed by the Quarkus platform for ensuring their compatibility. Ensure that you do not use the
RESTEasyandRESTEasy Reactiveextensions in the same project.The quark icon (
) next to an extension indicates that the extension is part of the Red Hat build of Quarkus platform release. Red Hat recommends that you use extensions from the same platform, because they are tested and verfied together, and thus are easier to use and upgrade.
You can enable the option to automatically generate starter code for extensions that are marked with CODE.
NoteRed Hat provides different levels of support for individual extensions on the list, which are indicated by labels next to the name of each extension:
- SUPPORTED Red Hat fully supports extensions for use in enterprise applications in production environments.
- TECH-PREVIEW Red Hat offers limited support to extensions in production environments under the Technology Preview Features Support Scope.
- DEV-SUPPORT Red Hat does not support extensions for use in production environments, but Red Hat developers support the core functionality that they provide for use in developing new applications.
- DEPRECATED Red Hat plans to replace extensions with more recent technology or implementation that provides the same functionality.
- CODE You can automatically generate the example code for extensions.
- Red Hat does not support the unlabeled extensions for use in production environments.
Expand the overflow menu (⌄) next to each of the extensions to access additional options that you can use to:
- add the extension to an existing project using the Quarkus maven plugin on the command line
-
copy an XML snippet to add the extension to a project’s
pom.xmlfile -
obtain the
groupId,artifactIdandversionof each extension open the extension guide
- Select Generate your application to confirm your choices and display the overlay screen with the download link for the archive that contains your generated project. The overlay screen also shows the custom command that you can use to compile and start your application.
- Select Download the ZIP to save the archive with the generated project files to your machine.
- Extract the contents of the archive.
Navigate to the directory that contains your extracted project files:
cd <directory_name>
cd <directory_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Compile and start your application in development mode:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.6. Configuring the Java compiler リンクのコピーリンクがクリップボードにコピーされました!
By default, the Quarkus Maven plug-in passes compiler flags to the javac command from the maven-compiler-plugin plug-in.
Procedure
To customize the compiler flags used in development mode, add a
configurationsection to thepluginblock and set thecompilerArgsproperty. You can also setsource,target, andjvmArgs. For example, to pass-verboseto both the JVM andjavacadd the following lines:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.7. Installing and managing Java extensions with Quarkus applications リンクのコピーリンクがクリップボードにコピーされました!
You can use Java extensions to expand the functionality of your application and to configure, boot, and integrate a framework into your application. This procedure shows you how to find and add extensions to your Quarkus project.
Prerequisites
- You have a Quarkus Maven project.
Procedure
- Navigate to your Quarkus project directory.
To list the available extensions, enter the following command:
./mvnw quarkus:list-extensions
./mvnw quarkus:list-extensionsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To add an extension to your project, enter the following command where
<extension>is the group, artifact, version (GAV) of the extension that you want to add:./mvnw quarkus:add-extension -Dextensions="<extension>"
./mvnw quarkus:add-extension -Dextensions="<extension>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to add the Agroal extension, enter the following command:
./mvnw quarkus:add-extension -Dextensions="io.quarkus:quarkus-agroal"
./mvnw quarkus:add-extension -Dextensions="io.quarkus:quarkus-agroal"Copy to Clipboard Copied! Toggle word wrap Toggle overflow To search for a specific extension, enter the extension name or partial name after
-Dextensions=. The following example searches for extensions that contain the textjdbc,agroal, andnon-exist-entin the name:./mvnw quarkus:add-extension -Dextensions=jdbc,agroal,non-exist-ent
./mvnw quarkus:add-extension -Dextensions=jdbc,agroal,non-exist-entCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command returns the following result:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To install all extensions that a specific text string returns, enter the extension name or partial name after
-Dextensions=. The following example searches for and installs all extensions that begin withhibernate-:./mvnw quarkus:add-extension -Dextensions="hibernate-*"
./mvnw quarkus:add-extension -Dextensions="hibernate-*"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.8. Importing your Quarkus project into an IDE リンクのコピーリンクがクリップボードにコピーされました!
Although it is possible to develop your Quarkus project in a text editor, you might find it easier to use an integrated development environment (IDE) to work on your project. The following instructions show you how to import your Quarkus project into specific IDEs.
Prerequisites
- You have a Quarkus Maven project.
Procedure
Complete the steps in one of the following sections:
CodeReady Studio or Eclipse
-
In CodeReady Studio or Eclipse, click File
Import. -
Select Maven
Existing Maven Project. - On the next screen, select the root location of the project. A list of the found modules appears.
- Select the generated project and click Finish.
To start your application, enter the following command in a new terminal window:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
IntelliJ
In IntelliJ, complete one of the following tasks:
-
Select File
New Project From Existing Sources. - On the Welcome page, select Import project.
-
Select File
- Select the project root directory.
- Select Import project from external model and then select Maven.
- Review the options and then click Next.
- Click Finish.
To start your application, enter the following command in a new terminal window:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Apache NetBeans
-
Select File
Open Project. -
Select the project
rootdirectory. - Click Open Project.
To start your application, enter the following command in a new terminal window:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Visual Studio Code
- Install the Java Extension Pack.
- In Visual Studio Code, open your project directory. The project loads as a Maven project.
1.9. Configuring the Quarkus project output リンクのコピーリンクがクリップボードにコピーされました!
Before you build your application, you can control the output of the build command by changing the default values of application properties in the application.properties file.
Prerequisites
- You have a Quarkus Maven project.
Procedure
-
Open the
application.propertiesfile in a text editor. Edit the values of properties that you want to change and save the file.
The following table list the properties that you can change:
Expand Property Description Type Default quarkus.package.main-classThe entry point of the application. In most cases, you should change this value.
string
io.quarkus.runner.GeneratedMainquarkus.package.typeThe requested output type.
string
jarquarkus.package.uber-jarWhether or not the Java runner should be packed as an uber-JAR.
boolean
falsequarkus.package.manifest.add-implementation-entriesWhether or not the implementation information should be included in the runner JAR file’s
MANIFEST.MFfile.boolean
truequarkus.package.user-configured-ignored-entriesFiles that should not be copied to the output artifact.
string (list)
quarkus.package.runner-suffixThe suffix that is applied to the runner JAR file.
string
-runnerquarkus.package.output-directoryThe output folder for the application build. This is resolved relative to the build system target directory.
string
quarkus.package.output-nameThe name of the final artifact.
string
1.10. Testing your Quarkus application in JVM mode with a custom profile リンクのコピーリンクがクリップボードにコピーされました!
Similar to any other running mode, configuration values for testing are read from the src/main/resources/application.properties file. By default, the test profile is active during testing in JVM mode, which means a resolution of properties will prefer values prepended with %test over values without a profile specification.
Suppose your application requires multiple test profiles. In that case, you need to run the same set of tests against different database instances. This is achievable by overriding the testing profile name, which can be done by specifying the system property quarkus.test.profile when executing Maven. By doing so, you will have control over what set of configuration values will be active during the test.
To learn more about standard testing demonstrated on the Starting With Quarkus example, see the Testing your Quarkus application with JUnit chapter of the Getting Started guide.
Prerequisites
- A Quarkus project created with Apache Maven.
Procedure
When running tests on a Quarkus application, the test configuration profile is set as active by default. However, it is possible to change this to a custom profile using the quarkus.test.profile system property.
- Run the following command to test your application:
mvn test -Dquarkus.test.profile=__<profile-name>__
mvn test -Dquarkus.test.profile=__<profile-name>__
+ NOTE: You cannot use a custom test configuration profile in native mode. Native tests always run under the prod profile.
1.11. Logging the Quarkus application build classpath tree リンクのコピーリンクがクリップボードにコピーされました!
The Quarkus build process adds deployment dependencies of the extensions that you use in the application to the original application classpath. You can see which dependencies and versions are included in the build classpath. The quarkus-bootstrap Maven plug-in includes the build-tree goal, which displays the build dependency tree for the application.
Prerequisites
- You have a Quarkus Maven application.
Procedure
Add the plug-in configuration to the
pom.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow To list the build dependency tree of your application, enter the following command:
./mvnw quarkus:dependency-tree
./mvnw quarkus:dependency-treeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The output of this command should be similar to the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The mvn dependency:tree command displays only the runtime dependencies of your application
1.12. Producing a native executable リンクのコピーリンクがクリップボードにコピーされました!
A native binary is an executable that can be run on a specific OS or CPU architecture, for which it was produced. An example of such an executable could be:
- an ELF binary for Linux
- a Universal binary for Mac
- an EXE binary for Windows
One advantage of building a native executable is to package the application and dependencies, including the JVM, in a single file. The native executable for your application then contains:
- the application code
- required libraries
- Java APIs
- a reduced version of the Java virtual machine (JVM) for improved application startup times and minimal disk and memory footprint
Globally, a user can select from two building options to produce a native executable from your Quarkus application:
- in-container build
local-host build
However, Red Hat build of Quarkus only supports in-container native compilation. For more details about local compilation, check the Building a native executable guide of the Upstream documentation.
| Building option | Requires | Uses | Results in | Benefits |
|---|---|---|---|---|
| In-container build - Supported | A container runtime such as Podman or Docker |
A builder image, which you can use together with RHEL8-UBI minimal, the Red Hat Universal Base Image: | Linux 64-bits executable | GraalVM does not need to be set up locally, which makes CI pipelines run more efficiently. |
| Local-host build - Only Upstream | A local installation of GraalVM or Mandrel |
Its local installation as a default for the | An executable, which has the same OS and CPU architecture as the machine on which the build is executed. | An alternative for developers that are not allowed or don’t want to use tools such as Docker or Podman. Overall faster than containers. |
1.12.1. Producing a native executable using an in-container build リンクのコピーリンクがクリップボードにコピーされました!
Prerequisites
- Podman or Docker is installed.
- The used container runtime must have access to the minimal amount of 8GB of memory.
Procedure
Open the Getting Started project
pom.xmlfile and verify that it includes thenativeprofile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteUsing the
nativeprofile allows you to create the native executable and run the native image tests.Build a native executable using one of the following methods:
Docker:
./mvnw package -Pnative -Dquarkus.native.container-build=true
./mvnw package -Pnative -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Podman:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow These commands create a
*-runnerbinary in thetargetdirectory, where:-
The
*-runnerfile is the built native binary produced by Quarkus. The
targetdirectory is a directory Maven creates when you build a maven application.ImportantCompiling a Quarkus application to a native executable consumes a lot of memory during analysis and optimization. You can limit the amount of memory used during native compilation by setting the
quarkus.native.native-image-xmxconfiguration property. Setting low memory limits might increase the build time. For more details, refer to Native executable configuration properties section of the Compiling your Quarkus applications to native executables.
-
The
Run the native executable:
./target/*-runner
./target/*-runnerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.12.2. Creating a container manually リンクのコピーリンクがクリップボードにコピーされました!
This section shows you how to manually create a container image with your application for Linux X86_64. When you produce a native image using the Quarkus Native container it creates an executable that targets the Linux X86_64 operating system. If your host operating system is different from this, you will not be able to run the binary directly and you will need to create a container manually.
Your Quarkus Getting Started project includes a Dockerfile.native in the src/main/docker directory with the following content:
Universal Base Image (UBI)
The following list displays the suitable images for use with Dockerfiles.
Red Hat Universal Base Image 8 (UBI8). This base image was designed and engineered to be the base layer for all of your containerized applications, middleware and utilities.
registry.access.redhat.com/ubi8/ubi:8.5
registry.access.redhat.com/ubi8/ubi:8.5Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Universal Base Image 8 Minimal (UBI8-minimal). A stripped down UBI8 image that uses microdnf as a package manager.
registry.access.redhat.com/ubi8/ubi-minimal:8.5
registry.access.redhat.com/ubi8/ubi-minimal:8.5Copy to Clipboard Copied! Toggle word wrap Toggle overflow - All Red Hat Base images are available in the Red Hat Ecosystem Catalog.
Procedure
Build a native Linux executable using one of the following methods:
Build a native executable with Docker:
./mvnw package -Pnative -Dquarkus.native.container-build=true
./mvnw package -Pnative -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Build a native executable with Podman:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Build the container image using one of the following methods:
Build the container image with Docker:
docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .
docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the container image with Podman
podman build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .
podman build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the container:
Run the container with Docker:
docker run -i --rm -p 8080:8080 quarkus-quickstart/getting-started
docker run -i --rm -p 8080:8080 quarkus-quickstart/getting-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container with Podman:
podman run -i --rm -p 8080:8080 quarkus-quickstart/getting-started
podman run -i --rm -p 8080:8080 quarkus-quickstart/getting-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.13. Testing the native executable リンクのコピーリンクがクリップボードにコピーされました!
Test the application in native mode to test the functionality of the native executable. Use the @NativeImageTest annotation to build the native executable and run tests against the HTTP endpoints.
Procedure
Open the
pom.xmlfile and verify that thenativeprofile contains the following elements:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
failsafe-maven-pluginruns integration test and indicates the location of the produced native executable.Open the
src/test/java/org/acme/quickstart/NativeGreetingResourceIT.javafile and verify that it includes the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the test:
./mvnw verify -Pnative
./mvnw verify -PnativeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows the output of this command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteQuarkus waits for 60 seconds for the native image to start before automatically failing the native tests. You can change this duration using the
quarkus.test.native-image-wait-timesystem property.You can extend the wait time using the following command where
<duration>is the wait time in seconds:./mvnw verify -Pnative -Dquarkus.test.native-image-wait-time=<duration>
./mvnw verify -Pnative -Dquarkus.test.native-image-wait-time=<duration>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.14. Using Quarkus development mode リンクのコピーリンクがクリップボードにコピーされました!
Development mode enables hot deployment with background compilation, which means that when you modify your Java files or your resource files and then refresh your browser, the changes automatically take effect. This also works for resource files such as the configuration property file.
Prerequisites
- You have a Quarkus Maven application.
Procedure
To start Quarkus in development mode, enter the following command in the directory that contains your Quarkus application
pom.xmlfile:./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Make changes to your application and save the files.
Refresh the browser to trigger a scan of the workspace.
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 appears.
In development mode, the debugger is activated and listens on port
5005.Optional: To wait for the debugger to attach before running the application, include
-Dsuspend:./mvnw quarkus:dev -Dsuspend
./mvnw quarkus:dev -DsuspendCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To prevent the debugger from running, include
-Ddebug=false:./mvnw quarkus:dev -Ddebug=false
./mvnw quarkus:dev -Ddebug=falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.15. Debugging your Quarkus project リンクのコピーリンクがクリップボードにコピーされました!
When Quarkus starts in development mode, debugging is enabled by default. The debugger listens on port 5005 without suspending the JVM.
Prerequisites
- You have a Quarkus Maven project.
Procedure
Use one of the following methods to control debugging:
Controlling the debugger through system properties
Change one of the following values of the
debugsystem property wherePORTis the port that the debugger is listening on:-
false: The JVM starts with debug mode disabled. -
true: The JVM starts in debug mode and is listening on port5005. -
client: The JVM starts in client mode and tries to connect tolocalhost:5005. -
PORT: The JVM starts in debug mode and is listening onPORT.
-
Change the value of the
suspendsystem property. This property is used when Quarkus starts in debug mode.-
yortrue: The debug mode JVM launch suspends. -
norfalse: The debug mode JVM starts without suspending.
-
Controlling the debugger from the command line
To start your Quarkus application in debug mode with JVM, enter the following command:
./mvnw quarkus:dev -Ddebug
./mvnw quarkus:dev -DdebugCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Enabling the debugger for a specific host domain
In development mode, the debugger is only enabled for applications that you execute on localhost. You must manually enable debugging on other hosts.
Use the
debugHostoption to enable debugging on a specific host. You must replace<host-ip-address>with the IP adress of the host for which you want to enable debugging../mvnw quarkus:dev -DdebugHost=<host-ip-address>
./mvnw quarkus:dev -DdebugHost=<host-ip-address>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To enable debugging on all hosts, replace
<host-ip-address>with0.0.0.:./mvnw quarkus:dev -DdebugHost=0.0.0.0
./mvnw quarkus:dev -DdebugHost=0.0.0.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow