Quarkus Cheatsheet (2022) - Mastertheboss
source link: http://www.mastertheboss.com/soa-cloud/quarkus/quarkus-cli-cheatsheet/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Here is a simple cheatsheet that will help you as reference guide to build your Quarkus applications. To learn how to install the Quarkus CLI we recommend to read this article: What’s new with Quarkus 2.0 and how to get started quickly).
Project setup
On-line project creator: https://code.quarkus.io/
Create a Quarkus basic REST project named “code-with-quarkus”
quarkus create
Create a Quarkus project using a specific BOM version:
quarkus create -P io.quarkus.platform:quarkus-bom:2.7.1.Final
Create a project using the Maven GAV com.foo:bar:1.0
quarkus create app com.foo:bar:1.0
Create a project using a Template:
#create a CLI project quarkus create cli #create an extension project quarkus create extension
Add / Remove extensions to a Quarkus project
# Add extension quarkus ext add kubernetes health # Remove extension quakus ext rm health
List available extensions for a search pattern (e.g. hibernate extensions)
quarkus ext list -i -s hibernate
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:
quarkus.http.port=9090
To Inject a System Property in your code, use the following annotation:
@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"
Database Access
Sample configuration for H2 Database (default profile):
quarkus.datasource.db-kind=h2 quarkus.datasource.jdbc.url=jdbc:h2:mem:school-timetabling;DB_CLOSE_DELAY=-1 quarkus.hibernate-orm.database.generation=drop-and-create
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK