Is it possible to attach the IntelliJ IDEA debugger to a running Java process? If yes, how?
-
3Of course. You need to create a "Remote" Run/Debug configuration. More here– VicJan 14, 2014 at 14:54
-
2Um, these command line arguments are READ ONLY as of 14.0.2. You can edit only a couple of them, which doesn't help solve the problem in this question. Any idea how to fix this?– marknuzzJan 28, 2015 at 6:04
-
Answer is here: stackoverflow.com/questions/51207430/…– RoutesMaps.comOct 9, 2018 at 20:45
-
See also Debug a java application without starting the JVM with debug arguments– VadzimFeb 28, 2020 at 22:42
5 Answers
Yes! Here is how you set it up.
Run Configuration
Create a Remote run configuration:
- Run -> Edit Configurations...
- Click the "+" in the upper left
- Select the "Remote" option in the left-most pane
- Choose a name (I named mine "remote-debugging")
- Click "OK" to save:
JVM Options
The configuration above provides three read-only fields. These are options that tell the JVM to open up port 5005 for remote debugging when running your application. Add the appropriate one to the JVM options of the application you are debugging. One way you might do this would be like so:
export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
But it depends on how your run your application. If you're not sure which of the three applies to you, start with the first and go down the list until you find the one that works.
You can change suspend=n
to suspend=y
to force your application to wait until you connect with IntelliJ before it starts up. This is helpful if the breakpoint you want to hit occurs on application startup.
Debug
Start your application as you would normally, then in IntelliJ select the new configuration and hit 'Debug'.
IntelliJ will connect to the JVM and initiate remote debugging.
You can now debug the application by adding breakpoints to your code where desired. The output of the application will still appear wherever it did before, but your breakpoints will hit in IntelliJ.
-
3The "Remote" option is absent in my Intellij IDEA 15.0.2 on mac os el capitan. How can I get that option? Mar 18, 2016 at 23:38
-
@user674669 I'm not sure. Maybe
Remote
is not available on the community edition? I'm using the paid version. Can anybody with the community edition confirm? Mar 28, 2016 at 20:03 -
@CoryKlein Do you know how to grab the output from
System.out.println
in IntelliJ when remote debugging? Apr 7, 2016 at 17:05 -
1@DonRhummy If you figure out how, I'd be happy to add that information to this answer, but AFAIK IntelliJ does not currently have support for piping stdout and stderr from a remote application back to IntelliJ. Apr 7, 2016 at 18:04
-
If the remote server is accessible only over ssh how do we specifiy the key file?– vachJun 29, 2016 at 10:28
It's possible, but you have to add some JVM flags when you start your application.
You have to add remote debug configuration: Edit configuration -> Remote.
Then you'lll find in displayed dialog window parametrs that you have to add to program execution, like:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Then when your application is launched you can attach your debugger. If you want your application to wait until debugger is connected just change suspend flag to y (suspend=y
)
-
It confused me that you edit the inputs below and these then update the option strings above (in 13.1 CE, at least.)– Carl GMay 28, 2014 at 17:08
-
7Um, these command line arguments are READ ONLY as of 14.0.2. You can edit a couple of them. Any idea how to fix this?– marknuzzJan 28, 2015 at 6:02
-
1
-
5First one worked for me. Note to others - I needed to specify this before the -jar flag.– jimDec 2, 2015 at 22:56
-
3@Nuzzolilo , the command line arguments displayed in idea are for display purposes only and hence they are read-only. They are not supposed to be added to idea but the remote java application which you want to debug. Sep 12, 2017 at 12:24
in AndroidStudio or idea
- Config the application will be debug, open Edit Configurations
add "VM Options" Config
“-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005”
remember "address"
- Config Remote Debugger if not exits, Click + to add
Also, don't forget you need to add "-Xdebug" flag in app JAVA_OPTS if you want connect in debug mode.
Also I use Tomcat GUI app (in my case: C:\tomcat\bin\Tomcat9w.bin).
Go to Java tab:
Set your Java properties, for example:
Java virtual machine
C:\Program Files\Java\jre-10.0.2\bin\server\jvm.dll
Java virtual machine
C:\tomcat\bin\bootstrap.jar;C:\tomcat\bin\tomcat-juli.jar
Java Options:
-Dcatalina.home=C:\tomcat
-Dcatalina.base=C:\tomcat
-Djava.io.tmpdir=C:\tomcat\temp
-Djava.util.logging.config.file=C:\tomcat\conf\logging.properties
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
Java 9 options:
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED