· 1 min read

Debug JAR Files in IntelliJ IDEA


Originally published on LinkedIn (May 2015).

I was working on CloudML — a deployment engine for provisioning and deploying multi-cloud applications — where the most common way to deploy an application (among a few available interfaces) is launching the cloudml-shell.jar file and running the deploy command from there.

Running CloudML from a JAR file gets in the way of debugging: I’m not launching a main() method from IntelliJ IDEA directly, just running a JAR from the console (Alt+F12), so IntelliJ has no running process of its own to attach to.

The fix: launch the JAR in debug mode (via JDWP — Java Debug Wire Protocol) and then attach IntelliJ to the already-running JVM. Here’s the sequence:

  1. Start the JAR with an extra flag (port is configurable — 5005 was IntelliJ’s default at the time):

    java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 your_jar_file.jar
  2. Create a Remote run configuration: Run → Edit Configurations → + → Remote.

    IntelliJ Run menu, Edit Configurations highlighted

    The Add New Configuration button in the Run/Debug Configurations dialog

    Selecting Remote from the list of configuration types

  3. Leave the default options (transport: Socket, debugger mode: Attach, host: localhost, port: 5005), then Apply and OK.

    The Remote configuration screen with default attach settings

  4. Since the JAR is already running, start the debug session directly — no need to launch anything new.

    Run menu now showing Debug for the new Remote configuration

    Selecting the Remote configuration from the debug toolbar dropdown

Hope this helps somebody.