I have successfully implemented my remote debugging for Spring boot applications in tomcat server for several times.
To make remote debug enable in tomcat server just need to change in catalina.sh and set: JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999 $JSSE_OPTS"
And start tomcat by catalina.sh jpda start
But I need to know how it works internally through this specific port over TCP network connection from IDE?
Related
I'm trying to enable JMX on tomcat docker image using docker-compose.yml but I'm still getting error that VisualVM cannot connect to the JMX.
tomcat:
image: tomcat:8.0-jre8
environment:
CATALINA_OPTS: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
ports:
- "9000:9000"
JMX requires more than just a single port since RMI is also involved. Remote JMX is always a challenge with Tomcat, and using Docker basically makes this "remote" access.
Have a look at Tomcat's JMX Remote Lifecycle Listener to see the port numbers that can be set, and use that listener to set them. If you don't, the RMI server is basically free to use whatever ports it wants to use and you can't predict them.
Once you set those ports, give the port mapping to Docker and you should be good to go.
I'm attempting to connect to a remote JMX service using VisualVM 1.3.8 with JRE 1.8.0. Making exactly the same connection with JConsole works perfectly, however the attempt to use the same parameters with VVM just hangs at the 'Adding services' stage. I've looked in the VVM log but there is literally nothing logged.
I also read here at the VVM remote JMX doc:
Note: To retrieve and display information on applications running on the remote host, the jstatd utility needs to be running on the remote host.
That puzzles me since I can make the remote JMX connection using JConsole and as far as I can tell, jstatd is not running on the remote.
Does anyone know if jstatd a requirement only for VVM as a remote JMX client? As the JMX connection can be made with JConsole between the same client and server endpoints, then there's no problem with network/firewall etc.
Other than that I'm really puzzled where else to look for clues?
I had the same trouble when I switched from Java 7 to 8, while using SOCKS where I was updating proxy settings through VisualVM -> Tools -> Plugins -> Settings -> Proxy Settings. However, I have been successful with the following:
Run your JVM with the following options:
-Dcom.sun.management.jmxremote.port=<JMX_PORT>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Note that you could obviously do something more secure, both w.r.t SSL and authentication.
Setup a SOCKS proxy from your localhost to the remote server:
ssh -D<SOCKS_PORT> -vvv -N <REMOTE_HOST>
Run either of these commands on your localhost:
jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=<SOCKS_PORT> service:jmx:rmi:///jndi/rmi://<REMOTE_HOST:JMX_PORT>/jmxrmi
jvisualvm -J-DsocksProxyHost=localhost -J-DsocksProxyPort=<SOCKS_PORT> --openjmx <REMOTE_HOST>
I've made a script called debug.sh and placed it under the bin directory (start it with ./debug.sh) to start Tomcat 8 in debugging mode:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
bash catalina.sh jpda start
But if it started, there is now message which says, that Tomcat is listening on port 8000. Also if I type
netstat -nat
there is no application listening on port 8000.
What exact configuration do I have to set, to remote debug my Tomcat 8 server which is running on a specific IP or do I have just a little problem in my script?
This answer has been updated following the comments, I did not understand the problem in the first place.
I guess you have followed that doc: this is about developing Tomcat itself.
I am not sure you are using the proper way to configure the port (I don't know your specific configuration details). In a standard environment, the ports are configured in the server.xml (note that several different ports are used by Tomcat for the different services).
To remotely monitor your server, you should use a JMX client. As far as I know, Eclipse doesn't include one (or at least not one documented) - you could code one as this is a Java specification (JSR262). You have one in a standard Java environement (JConsole). By default, JMX is not enabled on Tomcat. If you need to enable it, the fine way is to follow the doc.
Tomcat JMX monitoring and JConsole are both available in most versions of Tomcat and the Java runtime.
The following exchange seems to be about your problem.
I have an app deployed to my local WebLogic instance (10.3.6) on my Win7 laptop. It's creating Beans through Spring and registering them in the local MBeanServer. I can open up VisualVM, see the "WebLogic" process and see the mbeans that I've registered. This works fine.
I then wanted to set up my JVM for remote JMX access. I took the simple-minded approach for now and set the following properties:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true
I made sure the "jmxremote.access" and "jmxremote.password" file in my JRE was set appropriately.
I started it up, then opened up VisualVM on my Linux box and created a remote host entry for the IP address of my laptop, then a JMX connect to port 8888, and specified the name:pwd pair I set in the jmxremote.access and jmxremote.password files. This all worked fine. I could see all the same registered mbeans.
Then, I went back to my laptop and looked my local VisualVM, and I saw that there was no "WebLogic" process. It appears that enabling my JVM for remote JMX access has disabled local access. Is this supposed to happen? Is there a way to configure this? This isn't necessarily a big problem, I just need to understand it.
I have a few services set up in the SPring config to use RMI to invoke methods. In the test environment this resolves to the localhost, which could potentially allow me to debug the code. Unfortunately, it simply exectures the method and returns a value. Is there a way to setup intellij to debug RMI localhost requests?
What a problem to debug Spring RMI service? If you run it in Tomcat, just start tomcat as catalina.sh jpda run and in Idea create Remote Debug configuration, transport - socket, debugger mode - attach, host - localhost, port - usually 8000. That's all.