使用 Quarkus CLI 创建项目
- 使用 sdk 安装
sdk install quarkus- 创建应用
quarkus create && cd code-with-quarkus出现异常:
[ERROR] ❗ Unable to create project: Failed to resolve extension catalog of io.quarkus.platform:quarkus-qpid-jms-bom:pom:3.16.3添加参数,查看详细日志
quarkus create --verbose -e通过日志,发现是 maven 私服的问题,修改 settings.xml 文件,禁用 activeProfile 和 mirror。
- 启动应用
quarkus dev打开浏览器,访问 localhost:8080
注意:Quarkus 在开发模式会启动一个开发页面 http://localhost:8080/q/dev/
使用 Maven 创建项目
运行要求:
- JDK 17+ 并配置了
JAVA_HOME - Apache Maven 3.9.9
使用 maven 脚手架创建项目:
mvn io.quarkus.platform:quarkus-maven-plugin:3.16.3:create \ -DprojectGroupId=org.acme \ -DprojectArtifactId=getting-started \ -Dextensions='rest'cd getting-started运行项目:
./mvnw compile quarkus:dev访问 /hello
$ curl -w "\n" http://localhost:8080/helloHello from Quarkus REST可以修改 GreetingResource 类的输出内容,项目会自动编译和更新代码。再次访问 /hello,可以看到更新后的内容。
打包再运行项目:
./mvnw package -Dquarkus.package.jar.type=uber-jarjava -jar target/*-runner.jar创建本地可执行文件
./mvnw package -Dnative
# 没有安装 GraalVM,使用 docker 容器构建./mvnw package -Pnative -Dnative-image.docker-build=true使用 docker 容器镜像构建时,会在 src/main/docker 目录下生成 Dockerfile 文件:
- Dockerfile.jvm
- Dockerfile.legacy-jar
- Dockerfile.native
- Dockerfile.native-micro
Dockerfile.native 文件内容如下:
##### This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.## Before building the container image run:## ./mvnw package -Dnative## Then, build the image with:## docker build -f src/main/docker/Dockerfile.native -t quarkus/getting-started .## Then run the container using:## docker run -i --rm -p 8080:8080 quarkus/getting-started####FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10WORKDIR /work/RUN chown 1001 /work \ && chmod "g+rwX" /work \ && chown 1001:root /workCOPY --chown=1001:root target/*-runner /work/application
EXPOSE 8080USER 1001
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]创建一个 docker 镜像
docker build -f src/main/docker/Dockerfile.native -t quarkus/quarkus-project .运行镜像:
docker run -i --rm -p 8080:8080 quarkus/getting-started使用 code.quarkus.io
在 IntelliJ IDEA 创建项目
参考 IntelliJ IDEA 官方文档 Quarkus