webspherewebsphere-libertyopen-libertyliberty-maven-plugin

How can I start an Open Liberty server in debug mode with the liberty-maven-plugin "run" goal?


The liberty:run goal of the liberty-maven-plugin provides a single goal to create a server, install needed features and deploy my app, but what if I want to attach a debugger to step through my application?

The liberty:debug goal isn't the answer since it doesn't perform all these actions in a single goal.


Solution

  • For recent versions (since v3.1) of the liberty-maven-plugin, like:

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

    there are a couple options:

    1. Add a -Dliberty.jvm.debug property

    (using "run" as the OP asked about)

    $ mvn liberty:run -Dliberty.jvm.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777"
    

    Note the 'debug' part of the 'liberty.jvm.debug' property name can be any string.

    2. Use the liberty:dev mode (goal) instead

    (an even better, richer approach)

    The 'dev' goal will also install an Open Liberty server in the foreground, and deploy your app to it, (like 'run'), while also creating a file "watcher" to detect project changes, upon which it will automatically update your installation, rebuild and redeploy your app, and rerun your tests. (And you can attach the debugger by default).

    For more information see: