搜索

此内容没有您所选择的语言版本。

Chapter 6. Quarkus tools basics in CodeReady Studio

download PDF

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

The following section describes how to:

  • Create a new Quarkus project.
  • Run a Quarkus application.
  • Debug a Quarkus application.
  • Use Quarkus code completion.

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 New window appears.

  3. Enter Quarkus in the search field.
  4. Select Quarkus Project.
  5. Click the Next button.

    The New Quarkus project window appears.

  6. Select the project type.
  7. Name your project.
  8. Select the location for your project.
  9. Click the Next button.
  10. Ensure that the default values are correct.
  11. Click the Next button.

    The Quarkus extensions window appears.

  12. Select the appropriate Categories for your projects.

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

  13. Double-click on the extension to select or deselect it.

    The selected extensions appear in the Selected column.

  14. Click the Finish button.

Verification steps

  1. Click Window Show view Other.

    The Show View window appears.

  2. Enter Project Explorer in the search field.
  3. Select Project Explorer.
  4. Click the Open button.

    The Project Explorer view appears.

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 Run Run Configurations.

    The Run Configurations window appears.

  3. Scroll down to Quarkus Application.
  4. Right-click Quarkus Application New Configuration.
  5. Click the Browse button to locate your target project.
  6. Click the OK button.
  7. Click the Run button.

    The Console view appears.

Your application starts 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 Run Debug Configurations.
  3. Scroll down to Quarkus Application.
  4. Click the Debug button.

    The Console view appears.

Your Quarkus application starts and connects to a remote JVM debug configuration to your running Quarkus application. 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

6.4.1. Language support

Every Quarkus application is configured through an application.properties configuration file. The content of this configuration file is dependent of 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.

6.4.2. Using Quarkus code completion

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 project src main resources.
  4. Right-click application.properties Open With Generic Text Editor.

    The Text Editor window appears.

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

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

    Figure 6.1. CodeReady Studio code compilation invoked

    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.3. Enabling language support for MicroProfile

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 the target Quarkus project src/main/java.
  4. Right-click org.acme New Other.

    The New window appears.

  5. Enter file in the search field.
  6. Select File.
  7. Click the Next button.
  8. Name the file MyServiceClient.java.
  9. Click the Finish button.
  10. Paste the following content into the MyServiceClient.java 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
        @Path("/greet")
        Response greet();
    }
  11. Press Ctrl+S to save the changes.

Note that you can adjust the language support by changing the configuration key for the client from @RegisterRestClient to @RegisterRestClient(configKey = "myclient"). The language support will be adjusted accordingly.

Additional resources

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.