Chapter 6. Quarkus tools basics in CodeReady Studio

Quarkus is a Kubernetes-Native full-stack Java framework aimed to optimize work with Java virtual machines. Quarkus provides tools for Quarkus application developers, helping to reduce the size of Java applications and container image footprints, as well as the amount of memory required.

Prerequisites

6.1. Creating a new Quarkus project

The following section describes how to create a new Quarkus project in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Press Ctrl+N.

    The Select a wizard window appears.

    crs quarkus project wizard
  3. Enter Quarkus in the search field.
  4. Select Quarkus Project.
  5. Click Next.

    The New Quarkus project window appears.

    crs quarkus project creation
  6. Select the needed project type.
  7. Name your project.
  8. Select the location for your project.
  9. Click Next.

    The Project type window appears.

    crs quarkus default values
  10. Ensure that the default values are correct.
  11. Click Next.

    The Quarkus extensions window appears.

    crs quarkus extensions selection
  12. Select the needed Categories for your projects.

    The available extensions of the selected category are displayed in the Extensions column.

  13. Select the needed Extensions for your projects.

    Double-click on the extension to select or deselect it. The selected extensions appear in the Selected column.

  14. Click Finish.

Your newly created Quarkus project is now listed in the Project Explorer view.

6.2. Running a Quarkus application

The following section describes how to run a Quarkus application in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click RunRun Configurations.

    crs run configurations

    The Run Configurations window appears.

  3. Scroll down to Quarkus Application.

    crs quarkus new config
  4. Right-click Quarkus ApplicationNew Configuration.

    crs new quarkus configuration
  5. Name your configuration.
  6. Click Browse to locate your project.

    Note

    It is possible to add environment variables to your Quarkus project. To add a new environment variable, click Environmentadd and select a name and value.

    crs quarkus configuration environment variables
  7. Click Apply.
  8. Click Run.

    The Console view appears.

Your application will start after the built process.

6.3. Debugging a Quarkus application

The following section describes how to debug a Quarkus application in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click RunDebug Configurations.

    crs run debug config

    The Debug Configurations window appears.

    crs debug conf window
  3. Expand Quarkus Application.
  4. Select your configuration.
  5. Click Debug.

    The Console view appears.

Your Quarkus application starts and connects to a remote JVM debug configuration. If you set breakpoints in your application source files, the execution automatically stops after reaching the breakpoint.

6.4. Using language support in CodeReady Studio

Every Quarkus application is configured through an application.properties configuration file. The content of this configuration file is dependent on the set of Quarkus extensions that your application is using.

Quarkus Tools includes content assist, which provides code completion, validation, and documentation. Code completion allows you to quickly complete statements in your code. Multiple choices are available to you via popups. This language support is now available for Kubernetes, OpenShift, S2i, Docker properties, MicroProfile REST Client properties, and MicroProfile Health artifacts.
Note that language support for MicroProfile REST Client properties needs to be enabled separately. For more information, see Section 6.4.2, “Enabling language support for MicroProfile REST Client properties”.

6.4.1. Using Quarkus content assist

The following section describes how to use Quarkus application.properties content assist in CodeReady Studio.

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Start Project Explorer.
  3. Expand your Quarkus projectsrc/main/resources.
  4. Right-click application.propertiesOpen WithGeneric Text Editor.

    crs open quarkus project in gen text editor

    The Generic Text Editor window appears.

  5. Navigate to an empty line.
  6. Press Ctrl+Space to invoke code completion.

    The code completion suggestions appear. Hover the mouse over the suggestions to display documentation.

    devstudio quarkus code completion1

    If you enter a wrong value, the editor underlines the error with a red wavy line.

    devstudio quarkus code completion error

Additional resources

6.4.2. Enabling language support for MicroProfile REST Client properties

The following section describes how to enable language support for MicroProfile REST Client properties.

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Start Project Explorer.
  3. Expand your Quarkus projectsrc/main/java.
  4. Right-click org.acmeNewOther.

    The Select wizard window appears.

    crs new file creation
  5. Enter file in the search field.
  6. Select File.
  7. Click Next.

    The Create a new file resource window appears.

    crs new dotjava file
  8. Name your new file.
  9. Click Finish.
  10. Paste the following content into your newly created file:

    package org.acme;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.core.Response;
    
    import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
    
    @RegisterRestClient
    public interface MyServiceClient {
    	@GET
        ("/greet")
        Response greet();
    }
  11. Press Ctrl+S to save the changes.

Additional resources