[JAVA] Try Quarkus on IBM Cloud Shell

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.

What is Cloud Shell?

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. image.png

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. image.png

Launch Cloud Shell from IBM Cloud

-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. image.png -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. image.png **-Session1: Quarkus environment construction ** **-Session2: curl command execution ** **-Session3: File editing **

Step1: Run the sample code

Copy each line or $ to the clipboard and paste it into the Cloud Shell to proceed.

1. Git clone

git clone https://github.com/quarkusio/quarkus-quickstarts.git

2. Check the disk usage

df
image.png #### 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" ``` image.png #### 4. Move the directory and check the contents ``` $ cd getting-started $ ls ``` image.png #### 5. Check the contents of the file ``` $ cat pom.xml $ cat src/main/java/org/acme/getting/started/GreetingResource.java ``` image.png * The pom file has quarkus-bom and quarkus-maven-plagin set. image.png * GreetingResource.java will generate code like this. #### 6. Start Quarkus ``` ./mvnw compile quarkus:dev: ``` image.png I was able to start! Next, add Session2.

7. Run code with cUrl (Session 2)

curl -w "\n" http://localhost:8080/hello
image.png "Hello" was displayed as the return value! Next, add Session3.

Step2: Code modification

1. Check and move directories (Session3)

$ ls
$ cd getting-started
$ ls

2. Move directories and copy and confirm files

$ cd src/main/java/org/acme/getting/started
$ ls
$ cp GreetingResource.java GreetingService.java
$ ls
image.png #### 3. Check (display) the edited file ``` cat GreetingService.java ``` image.png ↓ Edit the contents next. ↓

4. Edit the Greeting Service file

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 image.png Display and confirm the edited file

cat GreetingService.java

5. Edit the GreetingResource file

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 

6. Run code with cUrl (Session 2)

$ 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)'
image.png

That's it for trying Quarkus on IBM Cloud Shell. Thank you for reading until the end. Thank you for your support!

Recommended Posts

Try Quarkus on IBM Cloud Shell
Launch an application on Code Engine using IBM Cloud Shell
Try using Firebase Cloud Functions on Android (Java)
Try DisplayLink on Ubuntu 20.04
Try running an app made with Quarkus on Heroku
Deploy Java apps on the IBM Cloud Kubernetes service
Try actions on GitHub [actions]
Try RabbitMQ + PHP on CentOS
Try Docker on Windows 10 Home
Update RVM on AWS Cloud9
Try Spring Boot on Mac