paulgreg
paulgreg

Reputation: 18903

What are Java command line options to set to allow JVM to be remotely debugged?

I know there's some JAVA_OPTS to set to remotely debug a Java program.

What are they and what do they mean ?

Upvotes: 403

Views: 584508

Answers (9)

Antony Shumskikh
Antony Shumskikh

Reputation: 1331

Since Java 9.0 JDWP supports only local connections by default. https://www.oracle.com/java/technologies/javase/9-all-relnotes.html#JDK-8041435

For remote debugging one should run program with *: in address:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000

Upvotes: 123

paulgreg
paulgreg

Reputation: 18903

Before Java 5.0, use -Xdebug and -Xrunjdwp arguments. These options will still work in later versions, but it will run in interpreted mode instead of JIT, which will be slower.

From Java 5.0, it is better to use the -agentlib:jdwp single option:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044

Options on -Xrunjdwp or agentlib:jdwp arguments are :

  • transport=dt_socket : means the way used to connect to JVM (socket is a good choice, it can be used to debug a distant computer)
  • address=8000 : TCP/IP port exposed, to connect from the debugger (will only allow local connections, see Antony Shumskikh's answer for remote debugging)
  • suspend=y : if 'y', tell the JVM to wait until debugger is attached to begin execution, otherwise (if 'n'), starts execution right away.

Upvotes: 528

neves
neves

Reputation: 39173

Here is the easiest solution for maven builds.

There are a lot of environment special configurations needed if you are using Maven. So, if you start your program from maven, just run the mvnDebug command instead of mvn, it will take care of starting your app with remote debugging configurated. Now you can just attach a debugger on port 8000.

It'll take care of all the environment problems for you.

Upvotes: 3

Hans Sjunnesson
Hans Sjunnesson

Reputation: 22289

I have this article bookmarked on setting this up for Java 5 and below.

Basically run it with:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044

For Java 5 and above, run it with:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044

If you want Java to wait for you to connect before executing the application, replace suspend=n with suspend=y.

Upvotes: 389

Prashant Jainer
Prashant Jainer

Reputation: 1

If you are using java 9 or higher, to remotely debug (which is also the case when you use docker at local) you have to provide --debug *:($port). Because from java 9 --debug ($port) will only allow to debug at local, not remotely.

So, you can provide command in docker-compose like command: -- /opt/jboss/wildfly/bin/standalone.sh --debug *:8787

Upvotes: -1

Boney
Boney

Reputation: 1770

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=PORT_NUMBER

Here we just use a Socket Attaching Connector, which is enabled by default when the dt_socket transport is configured and the VM is running in the server debugging mode.

For more details u can refer to : https://stackify.com/java-remote-debugging/

Upvotes: 1

Jovi Qiao
Jovi Qiao

Reputation: 101

java

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=y -jar target/cxf-boot-simple-0.0.1-SNAPSHOT.jar

address specifies the port at which it will allow to debug

Maven

**Debug Spring Boot app with Maven:

mvn spring-boot:run -Drun.jvmArguments=**"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8001"

Upvotes: 10

Santosh b
Santosh b

Reputation: 798

Command Line

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=PORT_NUMBER

Gradle

gradle bootrun --debug-jvm

Maven

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=PORT_NUMBER

Upvotes: 4

thebiggestlebowski
thebiggestlebowski

Reputation: 2779

For java 1.5 or greater:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

For java 1.4:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

For java 1.3:

java -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

Here is output from a simple program:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 HelloWhirled
Listening for transport dt_socket at address: 1044
Hello whirled

Upvotes: 14

Related Questions