Developing and compiling your Red Hat build of Quarkus applications with Apache Maven
Abstract
Providing feedback on Red Hat build of Quarkus documentation Copy linkLink copied to clipboard!
To report an error or to improve our documentation, log in to your Red Hat Jira account and submit an issue. If you do not have a Red Hat Jira account, then you will be prompted to create an account.
Procedure
- Click the following link to create a ticket.
- Enter a brief description of the issue in the Summary.
- Provide a detailed description of the issue or enhancement in the Description. Include a URL to where the issue occurs in the documentation.
- Clicking Submit creates and routes the issue to the appropriate documentation team.
Making open source more inclusive Copy linkLink copied to clipboard!
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
Chapter 1. Developing and compiling your Red Hat build of Quarkus applications with Apache Maven Copy linkLink copied to clipboard!
As an application developer, you can use Red Hat build of Quarkus to create microservices-based applications written in Java that run on OpenShift Container Platform and serverless environments. Applications compiled to native executables have small memory footprints and fast startup times.
Use the Quarkus Apache Maven plugin to create a Red Hat build of Quarkus project.
Where applicable, alternative instructions for using the Quarkus command-line interface (CLI) are provided. The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Prerequisites
You have installed OpenJDK 17 or 21.
- To download Red Hat build of OpenJDK, log in to the Red Hat Customer Portal and go to Software Downloads.
-
You have set the
JAVA_HOMEenvironment variable to specify the location of the Java SDK. You have installed Apache Maven 3.8.6 or later.
- To download Maven, go to the Apache Maven Project website.
1.1. About Red Hat build of Quarkus Copy linkLink copied to clipboard!
Red Hat build of Quarkus is a Kubernetes-native Java stack optimized for containers and Red Hat OpenShift Container Platform. Quarkus is designed to work with popular Java standards, frameworks, and libraries such as Eclipse MicroProfile, Eclipse Vert.x, Apache Camel, Apache Kafka, Hibernate ORM with Jakarta Persistence, and RESTEasy Reactive (Jakarta REST).
As a developer, you can choose the Java frameworks you want for your Java applications, which you can run in Java Virtual Machine (JVM) mode or compile and run in native mode. Quarkus provides a container-first approach to building Java applications. The container-first approach facilitates the containerization and efficient execution of microservices and functions. For this reason, Quarkus applications have a smaller memory footprint and faster startup times.
Quarkus also optimizes the application development process with capabilities such as unified configuration, automatic provisioning of unconfigured services, live coding, and continuous testing that gives you instant feedback on your code changes.
For information about the differences between the Quarkus community version and Red Hat build of Quarkus, see Differences between the Quarkus community version and Red Hat build of Quarkus.
1.2. About Apache Maven and Red Hat build of Quarkus Copy linkLink copied to clipboard!
Apache Maven is a distributed build automation tool that is used in Java application development to create, manage, and build software projects.
To learn more about Apache Maven, see Apache Maven documentation.
Maven repositories
A Maven repository stores Java libraries, plugins, 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 the Red Hat-hosted Maven repository with your Quarkus projects, or you can download the Red Hat build of Quarkus Maven repository.
Maven plugins
Maven plugins are defined parts of a POM file that run one or more tasks. Red Hat build of Quarkus applications use the following Maven plugins:
-
Quarkus Maven plugin (
quarkus-maven-plugin): Enables Maven to create Quarkus projects, packages your applications into JAR files, and provides a dev mode. -
Maven Surefire plugin (
maven-surefire-plugin): When Quarkus enables thetestprofile, the Maven Surefire plugin is used during thetestphase of the build lifecycle to run unit tests on your application. The plugin generates text and XML files that contain the test reports.
1.2.1. Configuring the Maven settings.xml file for the online repository Copy linkLink copied to clipboard!
To use the Red Hat-hosted Quarkus repository with your Quarkus Maven project, configure the settings.xml file for your user. Maven settings that are used with a repository manager or a repository on a shared server offer 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. If you want to apply the configuration to a specific project only, use the -s option and specify the path to the project-specific settings.xml file.
Procedure
Open the Maven
$HOME/.m2/settings.xmlfile in a text editor or an integrated development environment (IDE).NoteIf no
settings.xmlfile is present in the$HOME/.m2/directory, copy thesettings.xmlfile from the$MAVEN_HOME/conf/directory into the$HOME/.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.3. Creating a Red Hat build of Quarkus project on the command line Copy linkLink copied to clipboard!
Use the Red Hat build of Quarkus Maven plugin on the command line to create a Quarkus project by providing attributes and values on the command line or by using the plugin in interactive mode. You can also create a Quarkus project by using the Quarkus command-line interface (CLI). The resulting project includes 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
Prerequisites
You have installed OpenJDK 17 or 21.
- To download Red Hat build of OpenJDK, log in to the Red Hat Customer Portal and go to Software Downloads.
-
You have set the
JAVA_HOMEenvironment variable to specify the location of the Java SDK. You have installed Apache Maven 3.8.6 or later.
- To download Maven, go to the Apache Maven Project website.
- You have installed the Quarkus command-line interface (CLI), which is one of the methods you can use to create a Quarkus project. For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
In a command terminal, enter the following command to verify that Maven is using OpenJDK 17 or 21 and that the Maven version is 3.8.6 or later:
mvn --version
mvn --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow - If the preceding command does not return OpenJDK 17 or 21, add the path to OpenJDK 17 or 21 to the PATH environment variable and enter the preceding command again.
To create a project, use one of the following methods:
Use the Quarkus Maven plugin. 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:3.8.6.SP3-redhat-00002:create
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:3.8.6.SP3-redhat-00002:createCopy to Clipboard Copied! Toggle word wrap Toggle overflow When prompted, enter the required attribute values.
NoteYou can also create your project by using the default values for the project attributes by entering the following command:
mvn com.redhat.quarkus.platform:quarkus-maven-plugin:3.8.6.SP3-redhat-00002:create -BUse the Quarkus CLI. Enter the following command:
quarkus create app my-groupId:my-artifactId --package-name=getting.started
quarkus create app my-groupId:my-artifactId --package-name=getting.startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also get the list of available options with:
quarkus create app --help
quarkus create app --helpCopy to Clipboard Copied! Toggle word wrap Toggle overflow
By default, the Quarkus Maven plugin uses the latest preferred quarkus-bom version. The quarkus-bom file aggregates extensions so that you can reference them from your applications to align the dependency versions. When you are offline, the Quarkus Maven plugin uses the latest preferred version of the quarkus-bom from the last time it pulled updates from the Maven repository.
1.4. Creating a Red Hat build of Quarkus project by configuring the pom.xml file Copy linkLink copied to clipboard!
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 following items:
- The Maven Compiler Plugin version
-
The Quarkus BOM
groupID,artifactID, andversion - The Maven Surefire Plugin version
-
The
skipITsproperty.
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 plugin, the Maven Compiler plugin, and the Maven Surefire plugin:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe
maven-surefire-pluginruns the unit tests for your application.Optional: To build a native application, add a specific native profile that includes the
Maven Failsafe Plugin:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Tests that include
ITin their names and contain the@QuarkusIntegrationTestannotation are run against the native executable. - For more details about how native mode differs from JVM mode, see Difference between JVM and native mode in the Quarkus "Getting Started" guide.
-
Tests that include
1.5. Creating the Getting Started project by using code.quarkus.redhat.com Copy linkLink copied to clipboard!
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 that are required to compile your project into a native executable.
You can generate a Quarkus Maven project, including the following activities:
- 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 custom commands for compiling and starting your application
Prerequisites
- You have a web browser.
- You have prepared your environment to use Apache Maven. For more information, see Preparing your environment.
- You have configured your Quarkus Maven repository. To create a Quarkus application with Maven, use the Red Hat-hosted Quarkus repository. For more information, see Configuring the Maven settings.xml file for the online repository.
Optional: You have installed the Quarkus command-line interface (CLI), which is one of the methods you can use to start Quarkus in dev mode.
For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
- On your web browser, go to https://code.quarkus.redhat.com.
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 for the Maven artifacts generated by your project, such as
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 following setups:
- The directory structure of your generated project
- The format of configuration files that are 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:
- To display the fields that contain further application details, select More options.
-
Enter a version you want to use for artifacts generated by your project. The default value of this field is
1.0.0-SNAPSHOT. Using semantic versioning is preferred; however, you can choose to specify a different type of versioning. Select whether you want code.quarkus.redhat.com to add starter code to your project. When you add extensions that are marked with "STARTER-CODE" to your project, you can enable this option to automatically create example class and resource files for those extensions when you generate your project. However, this option does not affect your generated project if you do not add any extensions that provide an example code.
NoteThe code.quarkus.redhat.com application automatically uses the latest release of Red Hat build of Quarkus. However, should you require, it is possible to manually change to an earlier BOM version in the
pom.xmlfile after you generate your project, but this is not recommended.Select the extensions that you want to use. The Quarkus application includes the extensions you select as dependencies. The Quarkus platform also ensures these extensions are compatible with future versions.
ImportantDo not use the
RESTEasyand theRESTEasy 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 prefers using extensions from the same platform because they are tested and verified together and are therefore easier to use and upgrade.
You can enable the option to automatically generate starter code for extensions marked with "STARTER-CODE".
To confirm your choices, select Generate your application. The dialog box that appears displays the following items:
- A link to download the archive that contains your generated project
- A command that you can use to compile and start your application
- To save the archive with the generated project files to your machine, select Download the ZIP.
- Extract the contents of the archive.
Go to the directory that contains your extracted project files:
cd <directory_name>
cd <directory_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To compile and start your application in dev mode, use one of the following methods:
Using Maven:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev
quarkus devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
Support levels for Red Hat build of Quarkus extensions in the "Getting Started with Red Hat build of Quarkus" guide.
1.6. Configuring the Java compiler Copy linkLink copied to clipboard!
By default, the Quarkus Maven plugin passes compiler flags to javac command from maven-compiler-plugin.
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 the JVM andjavaccommands, add the following configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.7. Installing and managing extensions Copy linkLink copied to clipboard!
In Red Hat build of Quarkus, you can use extensions to expand your application’s functionality and 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 created a Quarkus Maven project.
- You have installed the Quarkus command-line interface (CLI), which is one of the methods you can use to manage your Quarkus extensions. For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
- Navigate to your Quarkus project directory.
List all of the available extensions by using one of the following ways:
Using Maven:
./mvnw quarkus:list-extensions
./mvnw quarkus:list-extensionsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus extension --installable
quarkus extension --installableCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Add an extension to your project by using one of the following ways:
Using Maven, enter the following command where
<extension>is the group, artifact, and 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 Using the Quarkus CLI, enter the following command where
<extension>is the group, artifact, and version (GAV) of the extension that you want to add:quarkus extension add '<extension>'
quarkus extension add '<extension>'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 textagroalin the name:./mvnw quarkus:add-extension -Dextensions=agroal
./mvnw quarkus:add-extension -Dextensions=agroalCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command returns the following result:
[SUCCESS] ✅ Extension io.quarkus:quarkus-agroal has been installed
[SUCCESS] ✅ Extension io.quarkus:quarkus-agroal has been installedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Similarly, with the Quarkus CLI, you might enter:
quarkus extension add 'agroal'
quarkus extension add 'agroal'Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.8. Importing your project into an IDE Copy linkLink copied to clipboard!
Although you can develop your Red Hat build of Quarkus project in a text editor, you might find using an integrated development environment (IDE) easier. The following instructions show you how to import your project into specific IDEs.
Prerequisites
- You have a Quarkus Maven project.
- You have installed the Quarkus command-line interface (CLI), which is required to start your project in dev mode. For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
Complete the required procedure for your IDE.
CodeReady Studio or Eclipse
- In CodeReady Studio or Eclipse, click File>*Import*.
- Select Maven → Existing Maven Project.
- Next, select the root location of the project. A list of the available modules appears.
- Select the generated project, and click Finish.
To compile and start your application, use one of the following ways:
Using Maven:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev
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 the project root directory.
- Select Import project from external model, and then select Maven.
- Review the options, and then click Next.
- Click Create.
To compile and start your application, use one of the following ways:
Using Maven:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev
quarkus devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Apache NetBeans
- Select File > Open Project.
-
Select the project
rootdirectory. - Click Open Project.
To compile and start your application, use one of the following ways:
Using Maven:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev
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.
Verification
The project loads as a Maven project.
1.9. Configuring the Red Hat build of Quarkus project output Copy linkLink copied to clipboard!
Before you build your application, you can control the build command output by changing the default values of the properties in the application.properties file.
Prerequisites
- You have created a Quarkus Maven project.
Procedure
-
Go to the
{project}/src/main/resourcesfolder, and open theapplication.propertiesfile in a text editor. Edit the values of properties that you want to change and save the file.
The following table lists the properties that you can change:
Expand Property Description Type Default quarkus.package.main-classThe entry point of the application. In most cases, you must change this value.
string
io.quarkus.runner.GeneratedMainquarkus.package.typeThe requested output type for the package, which you can set to 'jar' (uses 'fast-jar'), 'legacy-jar' for the pre-1.12 default jar packaging, 'uber-jar', 'native', or 'native-sources'.
string
jarquarkus.package.manifest.add-implementation-entriesDetermines whether the implementation information must be included in the runner JAR file’s
MANIFEST.MFfile.boolean
truequarkus.package.user-configured-ignored-entriesFiles that must 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 Red Hat build of Quarkus application in JVM mode with a custom profile Copy linkLink copied to clipboard!
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, meaning that properties prefixed with %test take precedence. For example, when you run a test with the following configuration, the value returned for the property message is Test Value.
message=Hello %test.message=Test Value
message=Hello
%test.message=Test Value
If the %test profile is inactive (dev, prod), the value returned for the property message is Hello.
For example, your application might require multiple test profiles to run a set of tests against different database instances. To do this, you must override the testing profile name, which can be done by setting the system property quarkus.test.profile when executing Maven. By doing so, you can control which sets of configuration values are active during the test.
To learn more about standard testing with the 'Starting With Quarkus' example, see Testing your Red Hat build of Quarkus application with JUnit in 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, you can change the profile to a custom profile by 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>__
You cannot use a custom test configuration profile in native mode. Native tests always run under the prod profile.
1.11. Logging the Red Hat build of Quarkus application build classpath tree Copy linkLink copied to clipboard!
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-maven-plugin Maven plugin includes the dependency-tree goal, which displays the build dependency tree for the application.
Prerequisites
- You have created a Quarkus Maven application.
Procedure
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 Example output. The exact output you see will differ from this 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 Copy linkLink copied to clipboard!
A native binary is an executable that is created to run on a specific operating system and CPU architecture.
The following list outlines some examples of a native executable:
- An ELF binary for Linux AMD 64 bits
- An EXE binary for Windows AMD 64 bits
- An ELF binary for ARM 64 bits
Only the ELF binary for Linux AMD 64 bits is supported in Red Hat build of Quarkus.
When you build a native executable, one advantage is that your application and dependencies, including the JVM, are packaged into a single file. The native executable for your application contains the following items:
- The compiled application code
- The required Java libraries
- A reduced version of the virtual machine (VM) for improved application startup times and minimal disk and memory footprint, which is also tailored for the application code and its dependencies
To produce a native executable from your Quarkus application, you can select either an in-container build or a local-host build. The following table explains the different building options that you can use:
| Building option | Requires | Uses | Results in | Benefits |
|---|---|---|---|---|
| In-container build - Supported | A container runtime, for example, Podman or Docker |
The default | A Linux 64-bit executable using the CPU architecture of the host | GraalVM does not need to be set up locally, which makes your CI pipelines run more efficiently |
| Local-host build - Only supported upstream | A local installation of GraalVM or Mandrel |
Its local installation as a default for the | An executable that has the same operating system and CPU architecture as the machine on which the build is executed | An alternative for developers that are not allowed or do not want to use tools such as Docker or Podman. Overall, it is faster than the in-container build approach. |
- Red Hat build of Quarkus 3.8 only supports the building of native Linux executables by using a Java 21-based Red Hat build of Quarkus Native builder image, which is a productized distribution of Mandrel. While other images are available in the community, they are not supported in the product, so you should not use them for production builds that you want Red Hat to provide support for.
- Applications whose source is written based on 17, with no Java 18 - 21 features used, can still compile a native executable of that application by using the Java 21-based Mandrel 23.1 base image.
- Building native executables by using Oracle GraalVM Community Edition (CE), Mandrel community edition, or any other distributions of GraalVM is not supported for Red Hat build of Quarkus.
1.12.1. Producing a native executable by using an in-container build Copy linkLink copied to clipboard!
To create a native executable and run the native image tests, use the native profile that is provided by Red Hat build of Quarkus for an in-container build.
Prerequisites
- Podman or Docker is installed.
- The container has access to at least 8GB of memory.
Procedure
Open the Getting Started project
pom.xmlfile, and verify that the project includes thenativeprofile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build a native executable by using one of the following methods:
Using Maven:
For Docker:
./mvnw package -Dnative -Dquarkus.native.container-build=true
./mvnw package -Dnative -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Podman:
./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Using the Quarkus CLI:
For Docker:
quarkus build --native -Dquarkus.native.container-build=true
quarkus build --native -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Podman:
quarkus build --native -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
quarkus build --native -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow Step results
These commands create a
*-runnerbinary in thetargetdirectory, where the following applies:-
The
*-runnerfile is the built native binary produced by Quarkus. The
targetdirectory is a directory that Maven creates when you build a Maven application.ImportantCompiling a Quarkus application to a native executable consumes a large amount 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.
To run the native executable, enter the following command:
./target/*-runner
./target/*-runnerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
- Native executable configuration properties in the "Compiling your Red Hat build of Quarkus applications to native executables" guide.
1.12.2. Producing a native executable by using a local-host build Copy linkLink copied to clipboard!
If you are not using Docker or Podman, use the Quarkus local-host build option to create and run a native executable.
Using the local-host build approach is faster than using containers and is suitable for machines that use a Linux operating system.
Red Hat build of Quarkus does not support using the following procedure in production. Use this method only when testing or as a backup approach when Docker or Podman is not available.
Prerequisites
A local installation of Mandrel or GraalVm, correctly configured according to the Building a native executable guide.
-
Additionally, for a GraalVM installation,
native-imagemust also be installed.
-
Additionally, for a GraalVM installation,
Procedure
For GraalVM or Mandrel, build a native executable by using one of the following methods:
Using Maven:
./mvnw package -Dnative
./mvnw package -DnativeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus build --native
quarkus build --nativeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Step results
These commands create a
*-runnerbinary in thetargetdirectory, where the following applies:-
The
*-runnerfile is the built native binary that Quarkus produces. The
targetdirectory is a directory that Maven creates when you build a Maven application.NoteWhen you build the native executable, the
prodprofile is enabled unless modified in thequarkus.profileproperty.
-
The
Run the native executable:
./target/*-runner
./target/*-runnerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
For more information, see the Producing a native executable section of the Quarkus "Building a native executable" guide.
1.12.3. Creating a container manually Copy linkLink copied to clipboard!
You can manually create a container image with your application for Linux AMD64. When you produce a native image by using the Quarkus Native container, the native image creates an executable that targets Linux AMD64. If your host operating system is different from Linux AMD64, you cannot run the binary directly and you 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 is designed and engineered to be the base layer for all of your containerized applications, middleware, and utilities.
registry.access.redhat.com/ubi8/ubi:8.9
registry.access.redhat.com/ubi8/ubi:8.9Copy 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.9
registry.access.redhat.com/ubi8/ubi-minimal:8.9Copy to Clipboard Copied! Toggle word wrap Toggle overflow - All Red Hat Base images are available on the Container images catalog site.
Procedure
Build a native Linux executable by using one of the following methods:
Docker:
./mvnw package -Dnative -Dquarkus.native.container-build=true
./mvnw package -Dnative -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Podman:
./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
./mvnw package -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Build the container image by using one of the following methods:
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-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the container by using one of the following methods:
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 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 Copy linkLink copied to clipboard!
Test the application in native mode to test the functionality of the native executable. Use the @QuarkusIntegrationTest annotation to build the native executable and run tests against the HTTP endpoints.
The following example shows how to test a native executable with a local installation of GraalVM or Mandrel. Before you begin, consider the following points:
- Red Hat build of Quarkus does not support this scenario, as outlined in Producing a native executable.
- The native executable you are testing with here must match the operating system and architecture of the host. Therefore, this procedure does not work on a macOS or an in-container build.
Procedure
Open the
pom.xmlfile and verify that thebuildsection has the following elements:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The Maven Failsafe plugin (
maven-failsafe-plugin) runs the integration test and indicates the location of the native executable that is generated.
-
The Maven Failsafe plugin (
Open the
src/test/java/org/acme/GreetingResourceIT.javafile and verify that it includes the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the test:
./mvnw verify -Dnative
./mvnw verify -DnativeCopy 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 60 seconds for the native image to start before automatically failing the native tests. You can change this duration by configuring the
quarkus.test.wait-timesystem property.You can extend the wait time by using the following command, where
<duration>is the wait time in seconds:./mvnw verify -Dnative -Dquarkus.test.wait-time=<duration>
./mvnw verify -Dnative -Dquarkus.test.wait-time=<duration>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note-
By default, native tests run by using the
prodprofile unless modified in thequarkus.test.native-image-profileproperty.
-
By default, native tests run by using the
1.14. Using Red Hat build of Quarkus development mode Copy linkLink copied to clipboard!
Development mode enables hot deployment with background compilation, which means that when you modify your Java or resource files and then refresh your browser, the changes automatically take effect. This also works for resource files such as the configuration property file. You can use either Maven or the Quarkus command-line interface (CLI) to start Quarkus in development mode.
Prerequisites
- You have created a Quarkus Maven application.
- You have installed the Quarkus CLI, which is one of the methods you can use to start Quarkus in development mode. For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
-
Switch to the directory that contains your Quarkus application
pom.xmlfile. To compile and start your Quarkus application in development mode, use one of the following methods:
Using Maven:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev
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 Red Hat build of Quarkus project Copy linkLink copied to clipboard!
When Red Hat build of Quarkus starts in development mode, debugging is enabled by default, and the debugger listens on port 5005 without suspending the JVM. You can enable and configure the debugging feature of Quarkus from the command line or by configuring the system properties. You can also use the Quarkus CLI to debug your project.
Prerequisites
- You have created a Red Hat build of Quarkus Maven project.
- You have installed the Quarkus command-line interface (CLI), which is one of the methods you can use to compile and debug your project. For more information, see Installing the Quarkus CLI.
The Quarkus CLI is intended for dev mode only. Red Hat does not support using the Quarkus CLI in production environments.
Procedure
Use one of the following methods to control debugging:
Controlling the debugger by configuring 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.
-
To suspend the JVM while running in debug mode, set the value of the
suspendsystem property to one of the following values:-
yortrue: The debug mode JVM launch suspends. -
norfalse: The debug mode JVM starts without suspending.
-
Controlling the debugger from the command line
To compile and start your Quarkus application in debug mode with a suspended JVM, use one of the following methods:
Using Maven:
./mvnw quarkus:dev -Dsuspend
./mvnw quarkus:dev -DsuspendCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev --suspend
quarkus dev --suspendCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Enabling the debugger for specific host network interfaces
In development mode, by default, for security reasons, Quarkus sets the debug host interface to localhost.
To enable the debugger for a specific host network interface, you can use the -DdebugHost option by using one of the following methods:
Using Maven:
./mvnw quarkus:dev -DdebugHost=<host-ip-address>
./mvnw quarkus:dev -DdebugHost=<host-ip-address>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the Quarkus CLI:
quarkus dev --debug-host=<host-ip-address>
quarkus dev --debug-host=<host-ip-address>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Where <host-ip-address> is the IP address of the host network interface that you want to enable debugging on.
To enable debugging on all host interfaces, replace <host-ip-address> with the following value:
0.0.0.0
0.0.0.0