Quarkus is a popular Java framework designed to build lightweight, fast, and efficient applications. It optimizes for container-based deployment, reducing memory consumption, and offering rapid startup times. This cheat sheet provides a quick reference guide to some of the most common commands you’ll use while working with Quarkus applications.
Project setup
On-line project Initializer: https://code.quarkus.io/
Create a Quarkus basic REST project “getting-started”
quarkus create app org.acme:getting-started
Create a project using Maven
mvn io.quarkus.platform:quarkus-maven-plugin:3.2.0.Final:create
Extensions
Add / Remove extensions to a Quarkus project
# Add extension quarkus ext add kubernetes # Remove extension quarkus ext rm health
List available extensions for a search pattern (e.g. hibernate extensions)
quarkus ext list -i -s hibernate
Build and Run applications
Build a Quarkus application
quarkus build
Run application in dev mode
quarkus dev
Run application in prod mode
java -jar target/quarkus-app/quarkus-run.jar
Configuration
The default configuration file is available in the folder src/main/resources/application.properties
Example: How to change the default HTTP Port and the Test Port:
quarkus.http.port=9090 quarkus.http.test-port=8083
Example YAML configuration:
quarkus: datasource: url: jdbc:postgresql://localhost:5432/some-database driver: org.postgresql.Driver
How to Inject a System Property in your code:
@ConfigProperty(name = "greeting" , defaultValue="hello") String greeting;
To list all available Configuration Options check this link: https://quarkus.io/guides/all-config
Using Profiles in your configuration
#Default profile. Used if there isn't a specific active profile for this property greeting="default" #Dev profile. Used in dev mode %dev.greeting="dev" #Prod Profile. Used in prod mode %prod.greeting="prod" #Test Profile. Used in test mode %test.greeting="test" #Custom profile. Requires -Dquarkus-profile=custom %custom.greeting="custom"
Logging
How to configure Console Logging level and a Logging Category
quarkus.log.console.level=DEBUG quarkus.log.category."com.sample".level=DEBUG
How to enable File Logging
quarkus.log.file.enable=true quarkus.log.file.path=/home/quarkus/logs/trace.log quarkus.log.file.level=TRACE
Database Access
Sample configuration for H2 Database (default profile):
quarkus.datasource.jdbc.url=jdbc:mariadb://localhost:3306/mydb quarkus.datasource.db-kind=mariadb quarkus.datasource.username=developer quarkus.datasource.password=developer quarkus.hibernate-orm.database.generation=update
Sample configuration for PostgreSQL Database (prod profile)
%prod.quarkus.datasource.db-kind=postgresql %prod.quarkus.datasource.username=quarkus_test %prod.quarkus.datasource.password=quarkus_test %prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test %prod.quarkus.datasource.jdbc.max-size=8 %prod.quarkus.datasource.jdbc.min-size=2 quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-orm.log.sql=true quarkus.hibernate-orm.sql-load-script=import.sql
Native executable
Build a native executable application (Using Docker Image of GraalVM)
service docker start quarkus build --native -Dquarkus.native.container-build=true target/code-with-quarkus-1.0.0-SNAPSHOT-runner
OpenShift deployment
How to deploy an application to OpenShift using the openshift extension:
mvn quarkus:add-extension -Dextensions="openshift" mvn clean package -Dquarkus.kubernetes.deploy=true
This cheat sheet covers some of the most common commands for working with Quarkus applications. Quarkus provides a vast array of features and capabilities, so make sure to explore the official documentation and community resources to dive deeper into the world of Quarkus development!
Found the article helpful? if so please follow us on Socials