back to all blogsSee all blog posts

MicroProfile Language Server Support for Open Liberty applications

image of author
Kathryn Kodama on Oct 8, 2020

The new MicroProfile Language Server provides added support for developing your MicroProfile applications with Open Liberty. Earlier this month, the first release of the Language Server for Eclipse MicroProfile (Eclipse LSP4MP), which is an open incubator project under the Eclipse Foundation, was published. The Tools for MicroProfile Visual Studio Code (VS Code) extension uses this language server, providing feature-rich support for MicroProfile APIs and properties in VS Code.

In this blog post, you will see how the new MicroProfile Language Server, along with existing tools for VS Code, makes it even easier to develop your Open Liberty applications.

Installing the extensions

Install the Extension Pack for MicroProfile from the VS Code Marketplace to support development of your Open Liberty applications with MicroProfile. In this blog, we’ll use the following extensions from the Extension Pack for MicroProfile:

Setting up the project

Create a new MicroProfile project

Generate a new Open Liberty Maven application with the MicroProfile Starter extension in VS Code:

  1. Run the MicroProfile: Generate a new MicroProfile Starter Project command from the VS Code command palette.

  2. Enter your desired groupId and artifactId.

  3. Select the latest MicroProfile Version (Version 3.3).

  4. Select Open Liberty as your runtime server.

  5. Select your desired Java version.

  6. Select the MicroProfile specifications that you would like included in your project.

  7. Select the folder that you’d like to generate your project into.

MicroProfile Starter for VS Code

Configure an existing project

You can modify an existing Maven or Gradle project for use with Open Liberty and MicroProfile.

For Maven projects, add the Liberty Maven Plugin to your pom.xml file:

<plugin>
    <groupId>io.openliberty.tools</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>3.3-M3</version>
</plugin>

Then, add the MicroProfile dependency to your pom.xml file:

<dependency>
    <groupId>org.eclipse.microprofile</groupId>
    <artifactId>microprofile</artifactId>
    <version>3.3</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

For Gradle projects, add the Liberty Gradle Plugin to your build.gradle file:

apply plugin: 'liberty'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'io.openliberty.tools:liberty-gradle-plugin:3.1-M2'
    }
}

Then, add the MicroProfile dependency to your build.gradle file:

dependencies {
    providedCompile 'org.eclipse.microprofile:microprofile:3.3'
}

Whether you have a Maven or Gradle project, add the MicroProfile features you would like to use in your Open Liberty server.xml file. For convenience, we specified the MicroProfile 3.3 feature to include all of the MicroProfile features:

<featureManager>
    <feature>microProfile-3.3</feature>
</featureManager>

Starting dev mode

Start your Open Liberty application in development mode, known as dev mode, by using the Liberty Dev Dashboard that’s provided by the Open Liberty Tools VS Code extension. Alternatively, you can start dev mode from the command line by running the mvn liberty:dev Maven goal or the gradle libertyDev Gradle task. Dev mode provides hot reload and deployment, so your code changes are automatically reflected in your running application.

Liberty Dev Dashboard in VS Code

Developing with MicroProfile language support

The MicroProfile Language Server provides useful features such as snippets, completion, hover, and diagnostics for both Java and properties files.

Coding assistance with Java source files

Use a snippet to quickly insert popular code blocks. For example, the mpreadiness snippet inserts a fully functional MicroProfile Health Readiness Check class. Open Liberty dev mode automatically picks up any changes and recompiles your source code so that you can immediately access your new class at the /health endpoint.

MicroProfile readiness snippet

The MicroProfile Language Server has knowledge of the MicroProfile APIs, meaning that the language server validates and corrects improper usage of MicroProfile APIs in your source code. For example, per the MicroProfile Health specification, all MicroProfile Health classes that use the @Readiness or @Liveness annotations must implement the HealthCheck class. If you used one of these annotations without implementing the HealthCheck class, the MicroProfile Language Server would correct you with a helpful diagnostic.

MicroProfile Health diagnostic

Coding assistance with MicroProfile properties files

The MicroProfile Language Server also provides useful features for your MicroProfile Config properties file.

With hover support, just hover over a MicroProfile property from within your Java code to see the value of that property.

MicroProfile Java properties hover

Did you reference a property in your source code that wasn’t implemented in your properties file? Code completion support, along with validation, helps you specify the correct property and type.

MicroProfile properties completion and diagnostic

Next steps

Using the tools in VS Code for Open Liberty and MicroProfile means that the finer details of your application, such as deployment and API usage, are handled for you. As a developer, you can code with greater efficiency and focus your efforts on the important aspects of your application.

This blog post highlighted just a few of the features provided by the MicroProfile Language Server. For more information, check out the full list of features or read the MicroProfile announcement blog post

Learn more about Open Liberty Tools for VS Code in the previous blog post.

Contribute to the code over on GitHub or open a GitHub issue if there are any features you want to see included in future versions of the MicroProfile Language Server.

Chat with us on Gitter:

Tags