This article is intended for those who are just starting Quarkus, using the IBM Cloud Shell provided by IBM Cloud to follow the First Start procedure of Quarkus.io. A guide to do this.
IBM Cloud Shell gives you instant access to the console from the cloud menu (icon). As of June 2020, the following features have been released as beta versions. ・ 30 hours use / week ・ Storage 500 MB / User ・ File upload and download processing ・ App preview Check IBM Cloud Docs for details and the latest information.
QUARKUS GET STARTED The original article is QUARKUS --CREATING YOUR FIRST APPLICATION here. https://quarkus.io/get-started/ You can follow this guide and edit the procedure for running IBM Cloud Shell. The scope introduced this time is the procedure for starting, modifying, and checking the execution result of the Quarkus application.
-Log in to IBM Cloud (https://ibm.biz/Bdqfyd). If you do not have an account, please register from here. An e-mail address is required for registration. This procedure can be done with a Lite account. (As of June 2020) -Start Cloud Shell. -This time, we will use 3 Sessions in Cloud Shell. Session can be added with the + button. You can use up to 5 Sessions in Cloud Shell. **-Session1: Quarkus environment construction ** **-Session2: curl command execution ** **-Session3: File editing **
Copy each line or $ to the clipboard and paste it into the Cloud Shell to proceed.
git clone https://github.com/quarkusio/quarkus-quickstarts.git
df
#### 3. Create Maven Project
```
mvn io.quarkus:quarkus-maven-plugin:1.6.0.Final:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=getting-started \
-DclassName="org.acme.getting.started.GreetingResource" \
-Dpath="/hello"
```
#### 4. Move the directory and check the contents
```
$ cd getting-started
$ ls
```
#### 5. Check the contents of the file
```
$ cat pom.xml
$ cat src/main/java/org/acme/getting/started/GreetingResource.java
```
* The pom file has quarkus-bom and quarkus-maven-plagin set.
* GreetingResource.java will generate code like this.
#### 6. Start Quarkus
```
./mvnw compile quarkus:dev:
```
I was able to start! Next, add Session2.
curl -w "\n" http://localhost:8080/hello
$ ls
$ cd getting-started
$ ls
$ cd src/main/java/org/acme/getting/started
$ ls
$ cp GreetingResource.java GreetingService.java
$ ls
#### 3. Check (display) the edited file
```
cat GreetingService.java
```
↓ Edit the contents next. ↓
nano GreetingService.java
(Opens an editing window) Edit (or replace) with the following contents
package org.acme.getting.started;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class GreetingService {
public String greeting(String name) {
return "hello " + name;
}
}
After editing the file, close with Exit → Y → To Files → GreetingService.java → Ent Display and confirm the edited file
cat GreetingService.java
Edit the GreetingResource file with the same procedure as below
$ cat GreetingResource.java
$ nano GreetingResource.java
(Opens an editing window) Edit (or replace) with the following contents
package org.acme.getting.started;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
@Path("/hello")
public class GreetingResource {
@Inject
GreetingService service;
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/greeting/{name}")
public String greeting(@PathParam String name) {
return service.greeting(name);
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
After editing the file, close with Exit → Y → To Files → GreetingResource.java → Ent Display and confirm the edited file
cat GreetingResource.java
$ curl -w "\n" http://localhost:8080/hello
$ curl -w "\n" http://localhost:8080/hello/greeting/quarkus
$ curl -w "\n" http://localhost:8080/hello/greeting/'Half-width alphanumeric character string ('is not required)'
That's it for trying Quarkus on IBM Cloud Shell. Thank you for reading until the end. Thank you for your support!
Recommended Posts