Riguz留言 | 贡献
无编辑摘要
Riguz留言 | 贡献
 
(未显示同一用户的2个中间版本)
第58行: 第58行:


= Development =
= Development =
== Build & Run ==
<syntaxhighlight lang="cpp">
$ quarkus dev
# or
$ ./mvnw compile quarkus:dev
</syntaxhighlight>
Access DEV UI: http://localhost:8080/q/dev-ui/
[[Image:quarkus-devui.png|600px]]
== Build native ==
== Build native ==
<ref>https://quarkus.io/guides/building-native-image</ref>


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
第79行: 第93行:
</syntaxhighlight>
</syntaxhighlight>


== Test native image==
<ref>https://quarkus.io/guides/getting-started-testing#quarkus-integration-test</ref>
<syntaxhighlight lang="cpp">
$ ./mvnw verify -Dnative
# By default, Quarkus waits for 60 seconds for the native image to start before automatically failing the native tests.
# ./mvnw verify -Dnative -Dquarkus.test.wait-time=300.
...
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.967 s -- in com.riguz.ystack.GreetingResourceIT
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- quarkus:3.25.3:native-image-agent (default) @ customer-service ---
[INFO]
[INFO] --- failsafe:3.5.3:verify (default) @ customer-service ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:15 min
[INFO] Finished at: 2025-08-15T00:02:55+08:00
[INFO] ------------------------------------------------------------------------
</syntaxhighlight>


[[Category:Quarkus]]
[[Category:Quarkus]]

2025年8月14日 (四) 16:03的最新版本

Why Quarkus

Quarkus is defined as a “Kubernetes Native Java stack tailored for OpenJDK HotSpot and GraalVM, crafted from the best of breed Java libraries and standards”

A Kubernetes native stack

Targeting Kubernetes as the target deployment platform, designed for containers as the main packaging format utilized in the cloud and by providing a toolset that allows you to build and deploy containers in a single step. Additionally, Quarkus supports a series of features that promote integration with the cloud platforms (e.g., exposing health-related information, external configuration options, etc.), which are integral to a positive user experience in the cloud environment

OpenJDK HotSpot and GraalVM

GraalVM compiler and the native image compilation, which are the main parts of GraalVM that Quarkus utilizes. Native compilation allows users to build a standalone binary executable that runs without requiring a JVM.

libraries and standards

Quarkus uses standards like MicroProfile (https://microprofile.io) and Jakarta EE (Enterprise Edition; https://jakarta.ee) and popular open source frameworks such as Hibernate (https://hibernate.org), Vertx (https://vertx.io), Apache Camel (https:// camel.apache.org), or RESTEasy (https://resteasy.dev). This allows developers to reuse their expertise and years of practice with these libraries when they start working with Quarkus

Get started

Install CLI

curl -Ls https://sh.jbang.dev | bash -s - trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/
curl -Ls https://sh.jbang.dev | bash -s - app install --fresh --force quarkus@quarkusio

Hello world

quarkus create && cd code-with-quarkus
$ quarkus dev
...
[INFO] Compiling 2 source files with javac [debug parameters release 21] to target/test-classes
Listening for transport dt_socket at address: 5005
__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2025-08-14 00:14:31,380 INFO  [io.quarkus] (Quarkus Main Thread) code-with-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.25.2) started in 2.921s. Listening on: http://localhost:8080

2025-08-14 00:14:31,386 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2025-08-14 00:14:31,387 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, rest, smallrye-context-propagation, vertx]

--
Tests paused
Press [e] to edit command line args (currently ''), [r] to resume testing, [o] Toggle test output, [:] for the terminal, [h] for more options>

Development

Build & Run

$ quarkus dev

# or
$ ./mvnw compile quarkus:dev

Access DEV UI: http://localhost:8080/q/dev-ui/

Build native

[1]

echo $GRAALVM_HOME
/Library/Java/JavaVirtualMachines/graalvm-jdk-24.0.2+11.1/Contents/Home
$ quarkus build --native
...
Finished generating 'customer-service-1.0.0-SNAPSHOT-runner' in 3m 20s.
./build/customer-service-1.0.0-SNAPSHOT-runner
__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2025-08-14 23:26:11,299 INFO  [io.quarkus] (main) customer-service 1.0.0-SNAPSHOT native (powered by Quarkus 3.25.3) started in 0.028s. Listening on: http://0.0.0.0:8080
2025-08-14 23:26:11,299 INFO  [io.quarkus] (main) Profile prod activated.
2025-08-14 23:26:11,299 INFO  [io.quarkus] (main) Installed features: [cdi, rest, smallrye-context-propagation, vertx]

Test native image

[2]

$ ./mvnw verify -Dnative
# By default, Quarkus waits for 60 seconds for the native image to start before automatically failing the native tests. 
# ./mvnw verify -Dnative -Dquarkus.test.wait-time=300.
...
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.967 s -- in com.riguz.ystack.GreetingResourceIT
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- quarkus:3.25.3:native-image-agent (default) @ customer-service ---
[INFO]
[INFO] --- failsafe:3.5.3:verify (default) @ customer-service ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:15 min
[INFO] Finished at: 2025-08-15T00:02:55+08:00
[INFO] ------------------------------------------------------------------------