Dev mode

When you run Open Liberty in dev mode, you can rapidly code, deploy, test, and debug applications directly from your integrated development environment (IDE) or text editor. You can enable dev mode to work with either Maven or Gradle build automation tools.

With dev mode, you can quickly iterate on changes to your code and get immediate feedback from on-demand or automatic unit and integration tests. You can also attach a debugger to step through your code at any time. Dev mode is available as a goal of the Open Liberty Maven plug-in or as a task of the Liberty Gradle plug-in. It integrates a set of capabilities for Open Liberty so that you can edit and monitor your application in real time, without restarting your running server. Dev mode addresses three primary focus areas: deploying changes, running tests, and debugging.

Run Open Liberty in dev mode

To run Open Liberty in dev mode, enable the Open Liberty Maven plug-in or the Open Liberty Gradle plug-in and run one of the following commands:

Maven: mvn liberty:dev

Gradle: gradle libertyDev

Detect, recompile, and deploy code changes

Dev mode can automatically detect, recompile, and deploy code changes whenever you save a new change in your IDE or text editor. Dev mode automatically detects the following changes to your application source:

  • Java source file and test file changes

  • Resource file changes

  • Configuration directory and configuration file changes

  • New dependency additions to your pom.xml file for Maven users or build.gradle file for Gradle users

  • New feature additions in the Open Liberty server configuration

Resource file, configuration file, and configuration directory changes are copied into your target directory. New dependencies in your pom.xml file or build.gradle file are added to your class path. New features are installed and started.

Some changes, such as adding certain configuration directories or files, do not take effect until you restart dev mode. To enable these changes, restart dev mode when prompted. To restart, first exit dev mode by pressing CTRL+C, or by typing q and pressing Enter. Then, run the mvn liberty:dev command or the gradle libertyDev command to restart. After the server restarts, the changes are detected, recompiled, and picked up by the running server.

You can configure how dev mode handles changes to your code by specifying parameters when you start dev mode. For more information about configuration parameters, see the dev goal of the Open Liberty Maven plug-in or the libertyDev task of the Open Liberty Gradle plug-in.

Run unit and integration tests on demand

You can run unit and integration tests on demand by pressing Enter in the command window where dev mode is running. Dev mode runs the unit tests and integration tests that are configured for your project. If you add a test to your project, dev mode compiles and includes it the next time that you run tests.

You can get immediate feedback on your changes by configuring dev mode to run hot tests. Hot tests are unit or integration tests that run automatically whenever you start dev mode or make a code change. To configure hot testing, specify the hot test parameter when you start dev mode, as shown in the following examples:

Maven: mvn liberty:dev -DhotTests

Gradle: gradle libertyDev --hotTests

You can also add parameters to specify whether to skip tests. For Maven, you can add parameters to skip unit tests, skip integration tests, or skip all tests. For Gradle, you can add a parameter to skip all tests. For more information about configuration parameters, see the dev goal of the Open Liberty Maven plug-in or the libertyDev task of the Open Liberty Gradle plug-in.

Attach a debugger to the running server

You can attach a debugger to the running server to step through your code at any time. You can specify breakpoints in your source code to locally debug different parts of your application. The default port for debugging is 7777. If the default port is not available, dev mode selects a random port to use as the port for debugging.

Open Liberty Tools for VS Code and IntelliJ

The Open Liberty Tools extensions for VS Code and IntelliJ integrate dev mode functions directly into your chosen IDE. After you install either of these extensions and enable either the Maven or Gradle plug-in, you can find your project name in the Liberty Dev Dashboard window in VS Code or IntelliJ IDEA. You can access dev mode functions by right-clicking your project name and selecting a command from the drop-down menu.

Container support for dev mode

If you are developing an application locally in a container, you can minimize differences between your development and production environments by running your containerized server in dev mode. With container support for dev mode, you can use the same Dockerfile for both development and production. You use the same base image and customizations, and specify the same configuration files in your Dockerfile that you use for your application in production.

Start dev mode with container support

For Maven projects, specify the Liberty Maven plug-in with version 3.3 in your project pom.xml file, as shown in the following example:

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

For Gradle projects, specify the Liberty Gradle plug-in with version 3.1 in your project build.gradle file, as shown in the following example:

apply plugin: 'liberty'

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

Create a Dockerfile in your project root directory that includes COPY commands for your application and configuration files. For more information, see the Open Liberty Docker image documentation.

To start dev mode with container support, run one of following commands in your project:

Maven: mvn liberty:devc

Gradle: gradle libertyDevc

These commands compile your application, build the development image, and run the server in the container. You can edit your source code or configuration files while dev mode is running. For a comprehensive demo of dev mode with container support, see the devc branch of the demo-devmode project.

For more information, see the documentation for the devc goal of the Liberty Maven plug-in or the libertyDevc task of the Liberty Gradle plug-in.

See also