此内容没有您所选择的语言版本。
Chapter 3. Creating the Getting Started project
The getting-started project lets you get up and running with a simple Quarkus application using Apache Maven and the Quarkus Maven plug-in.
Procedure
In a command terminal, enter the following command to verify that Maven is using JDK 11 and that the Maven version is 3.6.3 or higher:
mvn --version
mvn --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow - If the preceding command does not return JDK 11, add the path to JDK 11 to the PATH environment variable and enter the preceding command again.
To generate the project, enter one of the following commands:
NoteApple macOS and Microsoft Windows are not supported production environments.
If you are using Linux or Apple macOS, enter the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using the Microsoft Windows command line, enter the following command:
mvn io.quarkus:quarkus-maven-plugin:1.7.6.Final-redhat-00014:create -DprojectGroupId=org.acme -DprojectArtifactId=getting-started -DplatformGroupId=com.redhat.quarkus -DplatformVersion=1.7.6.Final-redhat-00014 -DclassName="org.acme.quickstart.GreetingResource" -Dpath="/hello"
mvn io.quarkus:quarkus-maven-plugin:1.7.6.Final-redhat-00014:create -DprojectGroupId=org.acme -DprojectArtifactId=getting-started -DplatformGroupId=com.redhat.quarkus -DplatformVersion=1.7.6.Final-redhat-00014 -DclassName="org.acme.quickstart.GreetingResource" -Dpath="/hello"Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using the Microsoft Windows Powershell, enter the following command:
mvn io.quarkus:quarkus-maven-plugin:1.7.6.Final-redhat-00014:create "-DprojectGroupId=org.acme" "-DprojectArtifactId=getting-started" "-DplatformGroupId=com.redhat.quarkus" "-DclassName=org.acme.quickstart.GreetingResource" "-Dpath=/hello"
mvn io.quarkus:quarkus-maven-plugin:1.7.6.Final-redhat-00014:create "-DprojectGroupId=org.acme" "-DprojectArtifactId=getting-started" "-DplatformGroupId=com.redhat.quarkus" "-DclassName=org.acme.quickstart.GreetingResource" "-Dpath=/hello"Copy to Clipboard Copied! Toggle word wrap Toggle overflow These commands create the following elements in the
./getting-starteddirectory:- The Maven structure
-
An
org.acme.quickstart.GreetingResourceresource exposed on/hello - An associated unit test
-
A landing page that is accessible on
http://localhost:8080after you start the application -
Example
Dockerfilefile insrc/main/docker - The application configuration file
After the directory structure is created, open the
pom.xmlfile in a text editor and examine the contents of the file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Quarkus BOM is imported into the
pom.xmlfile. Therefore, you do not need to list the versions of individual Quarkus dependencies in thepom.xmlfile. In addition, you can see thequarkus-maven-pluginplug-in that is responsible for packaging the application and providing the development mode.Review the
quarkus-resteasydependency in thepom.xmlfile. This dependency enables you to develop REST applications:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Review the
src/main/java/org/acme/quickstart/GreetingResource.javafile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This file contains the Java API for RESTful Web Services (JAX-RS) and a very simple REST endpoint that returns
helloto requests on/hello.NoteWith Quarkus, the
Applicationclass for JAX-RS is supported but not required. In addition, only one instance of theGreetingResourceclass is created and not one per request. You can configure this instance by using the different*Scopedannotations, for exampleApplicationScoped,RequestScoped, and so forth.