Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Building and running a jar

Dev mode is for development. On a server the application runs built: Maven compiles the code, Quarkus does its build-time processing, and the result goes into a folder you can copy to the server and start with plain Java. The server needs only a JDK or JRE of the same version as the build — no Maven and no sources.

Building

./mvnw package

The command compiles the code, runs the tests and builds the application. To skip the tests, add -DskipTests. The end of the output (shortened):

[INFO] --- quarkus:3.40.1:build (default-build) @ blog ---
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 15593ms
[INFO] BUILD SUCCESS

Augmentation is that build-time processing: Quarkus reads the annotations, generates code and prepares everything other frameworks do on every start.

What you get

target/quarkus-app/
├── quarkus-run.jar      the file to run
├── app/                 the application code
├── lib/                 libraries
│   ├── boot/
│   └── main/
└── quarkus/             classes generated at build time

This is the fast-jar format, the default one. Libraries are kept apart from the application code, so an update changes only the app folder, and a Docker image reuses the layer with the libraries.

Running

java -jar target/quarkus-app/quarkus-run.jar

Output shortened:

INFO  [io.quarkus] blog 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.40.1) started in 5.304s. Listening on: http://0.0.0.0:8080
INFO  [io.quarkus] Profile prod activated.
INFO  [io.quarkus] Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, hibernate-validator, jdbc-h2, micrometer, ...]

The prod profile is active: the %prod. settings apply, Dev Services and the Dev UI are off. The database is the data/blog.mv.db file from the database lesson. The 0.0.0.0 address means the application accepts requests on all network interfaces, not only on localhost.

curl http://localhost:8080/info

The answer is Anna's blog, 10 posts per page, owner: unknown — without "(dev)", because the %dev setting does not apply in prod.

Settings at startup

The built application does not need a rebuild for another port or database address. Settings are passed as environment variables or Java system properties:

QUARKUS_HTTP_PORT=9000 java -jar target/quarkus-app/quarkus-run.jar
java -Dquarkus.http.port=9000 -jar target/quarkus-app/quarkus-run.jar

Both commands start the application on port 9000.

One file: an uber-jar

If a single file is more convenient, build an uber-jar — a jar with all libraries inside:

./mvnw package -DskipTests -Dquarkus.package.jar.type=uber-jar
java -jar target/blog-1.0.0-SNAPSHOT-runner.jar

The blog-1.0.0-SNAPSHOT-runner.jar file is about 50 MB and starts the same way. The downside is that every update copies the whole file.

Common mistake

If you copy only quarkus-run.jar to the server, without the neighbouring folders, it does not start:

Error: Could not find or load main class io.quarkus.bootstrap.runner.QuarkusEntryPoint
Caused by: java.lang.ClassNotFoundException: io.quarkus.bootstrap.runner.QuarkusEntryPoint

quarkus-run.jar is almost empty and refers to lib/, app/ and quarkus/. Copy the whole target/quarkus-app folder or build an uber-jar.

Thanks for reading!

Donate to the site — we work hard for you.