Skip to content

Latest commit

 

History

History
236 lines (141 loc) · 16.9 KB

user-guide.md

File metadata and controls

236 lines (141 loc) · 16.9 KB

Liberty Tools for Visual Studio Code User Guide

This guide provides detailed instructions on how to configure your Liberty project to use the Liberty Tools for Visual Studio Code extension. For information regarding known issues and limitations, refer to our Common Issues wiki page or our Known Problems and Limitations wiki page.

Before you begin

Software requirements

  • Visual Studio Code 1.78.0 or later.
  • Java 17 or later is required by Liberty Tools for Visual Studio Code. To point Visual Studio Code to a specific runtime, see Settings for more information.

Application requirements

Configure your Java runtime for language servers

Liberty Tools for Visual Studio Code requires Java 17 or later to ensure that the following language servers start properly:

A toast message alerts you if any language server fails to run or if Visual Studio Code has trouble locating your Java.

To resolve this issue, you can define settings in your Visual Studio Code settings.json file or set system environment variables to point Liberty Tools to Java 17 or later.

For both Liberty Config Language Server and Eclipse Language Server for Jakarta EE, Liberty Tools for Visual Studio Code will check for the Java versions in the following order:

  1. java.jdt.ls.java.home in settings.json
  2. The embedded JRE included by Language Support for Java(TM) by Red Hat.
  3. JDK_HOME or JAVA_HOME as system environment variables. (Note: if both JDK_HOME and JAVA_HOME are set, JDK_HOME will take precedence)

By default, Liberty Tools installs the latest version of the Language Support for Java(TM) by Red Hat extension. The latest version contains an embedded JRE higher than Java 17 and therefore no additional configuration is required. However, if using an older version of the Language Support for Java(TM) by Red Hat extension or using the universal version without the embedded JRE causes an issue, then java.jdt.ls.java.home or one of JDK_HOME or JAVA_HOME must be configured to use Java 17 or later.

For LemMinX, Liberty Tools for Visual Studio Code will check for the Java versions in the following order:

  1. xml.java.home in settings.json
  2. JDK_HOME or JAVA_HOME as system environment variables. (Note: if both JDK_HOME and JAVA_HOME are set, JDK_HOME takes precedence)

settings.json example

External extension settings

Setting Description Provided By
maven.executable.path Maven commands executed by dev mode honour this setting. When this value is empty, dev mode tries to use mvn or mvnw according to the value of maven.executable.preferMavenWrapper. Maven for Java extension
maven.executable.preferMavenWrapper Maven commands executed by dev mode honour this setting. If this setting set to true, dev mode tries to use mvnw if a Maven wrapper file can be found. Otherwise, it uses mvn. Maven for Java extension
java.import.gradle.wrapper.enabled Gradle commands executed by dev mode honour this setting. If this setting is set to true, dev mode tries to use gradlew if a Gradle wrapper file can be found. Otherwise, it uses gradle. Language support for Java extension
xml.java.home This setting allows a user to define their LemMinX language server runtime without altering the JAVA_HOME environment variable. Not set
java.jdt.ls.java.home This setting specifies the folder path to the JDK (17 or later) that is used to launch the Java Language Server. This setting replaces the Java extension's embedded JRE to start the language servers. Not set

Open the Liberty dashboard

By default, the Liberty dashboard appears in the Project Explorer side bar. Optionally, you can drag the Liberty dashboard into the Activity Bar.

Side Bar view Activity Bar view
Liberty Dashboard Side Bar view Liberty Dashboard Activity Bar view

Projects that are already properly configured to run on Liberty and use Liberty dev mode are automatically added the Liberty dashboard when it opens. If your Liberty project does not show up in the Liberty dashboard automatically and you have the Liberty Maven or Liberty Gradle plugin configured, check out how to manually add your project to the Liberty dashboard.

If you add new projects or make changes, use the refresh icon in the Liberty dashboard toolbar to refresh the dashboard view.

Dashboard Refresh highlighted

Run your application on Liberty using dev mode

The following three menu actions are available to start your Liberty application in dev mode through the Liberty dashboard or the Visual Studio Code command palette:

Use the Liberty dashboard

The Liberty dashboard provides a context menu for Liberty projects. You can choose different commands from the menu to speed up application development.

Dashboard context menu

Use the Visual Studio Code Command Palette

The Liberty Tools plugin provides a set of commands to the command palette. The command palette is accessible a number of ways. Additionally, the Shift + Alt + L shortcut shows a similar menu with only Liberty commands.

All Liberty Tools commands that are described in the following sections are also available from the command palette.

Liberty Command Palette

Start your application in dev mode

To start your application in dev mode, select the Start command for your application in the Liberty dashboard.

A new terminal tab opens to run the application in dev mode.

Start command started

Start your application in dev mode with configuration

To start your application in dev mode with custom configuration, select the Start... command for your application in the Liberty dashboard. The command opens an edit dialog where you can specify parameters for the Liberty Maven dev goal or Liberty Gradle dev task.

Liberty Start... command

A new terminal tab opens to run the application in dev mode.

Liberty Start... command running in terminal

The next time you choose to start dev mode with configuration, the menu provides a history of previously used configurations.

Liberty Start... history

Start your application in dev mode in a container

To use dev mode for containers, select the Start in container command for your application in the Liberty dashboard.

Liberty Start in container command

For more information on dev mode for containers, check out the Liberty Maven devc goal or the Liberty Gradle libertyDevc task.

Run your application tests

After your application is running on Liberty using dev mode, you can easily run the tests provided by your application.

To run tests, select the Run tests command for your application in the Liberty dashboard.

The tests are run in the corresponding terminal.

Liberty run tests command

View your application test reports

After you finish running your application tests, you can access the produced test reports.

Liberty show test results

Maven-built applications

To view the integration test report for Maven-built applications, select the View integration test report command for your application in the Liberty dashboard.

This command looks for the integration test report at the /target/site/failsafe-report.html default location.

To view the unit test report for Maven-built applications, select the View unit test report command for your application in the Liberty dashboard.

This command looks for the unit test report at the/target/site/surefire-report.html default location.

Gradle-built applications

To view the test report for Gradle-built applications, select the View test report command for your application in the Liberty dashboard.

This command looks for the test report at the build/reports/tests/test/index.html default location.

Stop your application

To stop your application, select the Stop command for your application in the Liberty dashboard.

Stop command

Debug your application

To attach the debugger, you must have a running server. Once the server is running, click the Attach debugger command or select the Liberty: Attach debugger command in the command palette, followed by your application.

Attach Debugger

When the debugger is attached, the Visual Studio Code debug options become available.

Debug Mode

Manually add your Liberty project to the dashboard

In the event that your Liberty project is not automatically detected by the Liberty dashboard, you can manually add your Liberty project to the Liberty dashboard. To manually add your Liberty project to the Liberty dashboard, right-click into an empty space in the project explorer and select Add project to Liberty Dashboard or select the Liberty: Add project to the tool window command in the command palette, followed by your application.

Liberty add project to tool window

You are prompted with a list of projects that are not already displayed in the in the Liberty dashboard.

Liberty add project to tool window selection

To remove manually added Liberty projects from the Liberty dashboard, right-click in an empty space in the project explorer and select Remove project from Liberty Dashboard or select the Liberty: Remove project from the tool window command in the command palette, followed by your application.

Liberty Remove Project

Configure a Liberty server

Liberty configuration assistance provides editing assistance, such as code completion, diagnostics, and quick-fixes, in Liberty server.xml, server.env, and bootstrap.properties files.

  1. Start the project in dev mode by using one of the previously described Liberty dashboard or command palette commands. Dev mode installs the Liberty features that are required for your application.
  2. Open any of the supported Liberty configuration files.
  3. To use Liberty-specific code completion, press Ctrl + Space / Cmd + Space anywhere within the document. A drop-down list of completion suggestions appears.

LCLS server.xml completion

Liberty configuration assistance is offered through the Liberty Config Language Server. For more information, see the project documentation in GitHub.

Develop with Jakarta EE and MicroProfile APIs

Liberty Tools editing assistance provides code completion, diagnostics, and quick-fixes in configuration and application files for Jakarta EE and MicroProfile APIs.

  1. Open a Java or microprofile-config.properties file.
  2. To use Jakarta EE-specific and MicroProfile-specific code completion, press Ctrl + Space / Cmd + Space anywhere within the document. A drop-down list of completion suggestions appears.

Eclipse LSP4Jakarta RESTful completion

Eclipse LSP4MP microprofile-config.properties completion

  1. To use Jakarta EE-specific and MicroProfile-specific quick-fixes, hover over a Jakarta EE or MicroProfile diagnostic. A pop-up dialog appears that contains the diagnostic message and a Quick Fix link, if a quick-fix is available. Click the Quick Fix... link to view a list of quick-fix options.

Jakarta EE quick fix

Jakarta EE API configuration assistance is offered through Eclipse LSP4Jakarta, the Language Server for Jakarta EE. For more information, see the project documentation in GitHub.

MicroProfile EE API configuration assistance is offered through Eclipse LSP4MP, the Language Server for MicroProfile. For more information, see the project documentation in GitHub.