How to attach a debugger to WAS? - java

I need to attach a debugger to a remote instance of WAS and know that debugging is enabled. The problem is getting WID or whatever IDE I wanted connected to the server so I can step through the code.
I tried using Netbeans to connect and I get handshake failed, connection interrupted. The debugger is listening on port 7777. If I go into the WID admin console, I need a username and password. Would I need the same to attach a debugger, if so, where can I specify that?
Walter

Can you not add the following line to the startup script's parameters of WAS:
-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7777
And then attach your Netbeans remote debugger on port 7777

WAS can be configured for remote debugging via the web administration console.
It is also possible to configure this without starting WAS - via one of the profile XML files. But I don't remember the details and don't have WAS handy to check.

I think I simply need to enable the service at startup then I should be able to connect? I have to get permission first to do so.

Related

Remote debugging via IntellijIdea

I want to configure debugging flow for the application that is placed on a dedicated Linux server. I can connect to the server via SSH for now(with private key protection). F.E. ssh -i private_key.txt user#host. But I can't create a connection to the server via Intellij Idea to debug remotely(sample on the picture).
Q: do I need to add some properties to the java application. Or I need to build a connection in a different way.
You need to start the JVM on a remote host with the command line IDE shows you. And make sure the port and host that are specified in this command is accessible from the host where IDE is running.

How do I debug Java servlet filters, on-the-fly, from a remote machine (I'm using Eclipse and Apache Tomcat 5.5)

I wrote a Java servlet filter on my local machine and deployed it a remote (machine) web server. Unfortunately, it's been very difficult and time-consuming trying to trace errors reported by Apache Tomcat 5.5, my JSP/servlet engine. I can't keep writing System.out.println(...), saving, deploying, testing JSP pages, and so on. It's taking too long. There has to be a better, faster way.
Is it possible to remotely debug servlet filters? I don't have a web server on my local machine, which is why I'm asking about remote debugging. Specifically, I'm looking for a way to debug, line-by-line, the servlet filter, on-the-fly, as it's happening on the remote web server. Does such a method exist?
Or, is there a better method than writing to standard output. It's taking too long and I feel that must be a more efficient means of debugging Java servlet filters.
Note: I'm using Eclipse for development.
Thank you very much for any help.
Update
Thank you all for your help. I really appreciate it.
I added the JVM argument to Tomcat, restarted Tomcat. Then, on the machine with Eclipse, I entered in the appropriate info in the Debug config, put the breakpoint in, and tested. Unfortunately, it did not work. In the config, I left it as Socket Attach, clicked apply, and that was it. I pressed the debug button and it said the connection was refused. I tried ports 8000 and 8001 and both did not work.
Let me explain what I'm trying to do, that might be better.
I have a login page called login.jsp. On that page, is a form whose action attribute is servlet/LoginServlet. When the user submits the form, it calls servlet/LoginServlet, which is mapped to a class in the web.xml file. Let's call this class com.mysite.mypkg.classA. In class A, it calls a method from another class called com.custom.mypkg.classB. I want to put a breakpoint in classB.
So, using the url with login.jsp page in the Eclipse debugger won't call it. I tried using servlet/LoginServlet and that also did not work.
What should I put in for the URL? Or, do I debug this type of setup?
Thank you.
Update 2
I found this site here, which is pretty comprehensive. I ran netstat -a and noticed that the debug port is not listed. Windows Firewall is turned off, but there could be another thing blocking the port, who knows. Anyway, I placed the VM argument here and it's not working.
Thank you.
For remote debugging you need to start the server in debug mode. There are couple of ways doing that.
1 > start the server using
catinlina.bat jpda start
2 > Add an jvm argument to the tomcat java process
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Once the server is started in debug mode , you need to change the perspective of the project in eclipse to debug.
Then go to Run - > Debug configuration.
Double click remote java application and enter the details such as
Remote IP address
Debug port . Default tomcat debug port is 8000. If you use jvm argument, use the port mentioned in the jvm argument.
Click Apply
Go to the java file you want to debug.
Put a break point in the source code and run the scenario you want to test (Eg Web application using browser)
Also , ensure that the code in the java file is in sync with code deployed on remote server.
Happy Debugging!!!
Peace.
Sanket Raut
You can attach a debugger to a running Tomcat instance, provided that you gave it the right command line options when you launched it.
The Tomcat Development Wiki explains how to do this, and as a bonus gives you instructions on how to set up to debug from the Eclipse or NetBeans IDEs.
Of course, attaching a debugger to a running Tomcat has both security and performance implications*.
* And OH&S issues - you might get badly scratched if you tried this on the wrong kind of tomcat ...
You should run your remote tomcat with the following starup parameter:
bin/catalina.bat jpda start
Then in Eclipse on your local machine go to Run -> Debug Configurations -> Remote Java Application, create new configuration here, use IP of the remote machine as a host and 8000 as a port there
Run this configuration and use the breakpoints in Eclipse for debugging

Remote Debugging with Intellij Idea

I came to know of the remote debugging procedure under Idea recently. What I do is copy the configuration of remote debug under Run | Debug Configuration in Idea to the command line java execution parameters. The actual command line parameters are:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
If it is a script, I add these commands to it. By doing so, the command line displays the message:
Listening for transport dt_socket at address: 8000
So the debugging can happen using the local source code. However, I don't properly understand how remote debugging work. Anyone who knows how remote debugging actually works, please give me an explanation.
Thank you!
Remote debugging means that you can run your Java code anywhere, either on the local or remote machine. When it's running in the debug mode, you can connect to it from the IDE using TCP network connection and perform debugging. IDE needs to have the source code for the running classes so that you can place breakpoints inside this code and perform stepping, inspecting variables, etc.
If you are interested in technical details, refer to the JPDA documentation.
Consider a scenario where you want to fix something in your application but your application only can run over a server machine because of other dependencies.
That is where Remote Debugging come into picture. You Just connect the sever by providing the hostname and port and connect it with your respective environment.
How It works:
Application to be debugged will attach a socket to itself and then will start listening debug instructions.
Debugger will bind itself to that socket and then send instructions.
This is best way to test your code which are in different environment .
we need to have below points for sure before you are using remote debug .
we are using JBOSS in our servers.
configure - JBOSS_HOME/bin/run.conf
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
now add the server IP and port number into the intellij remote debugging .
4.your should have the latest version of the project in local that is in synch with the server else debug will not be allowed.
you need to start the intellij server for the project .
Then start the remote debug .
place a debug point in local and when we start testing in the server , when it hits the debug point it will stop and wait untill you process it .
The other point is , it will hold all the request in the queue and will not allow anyone to go through the break point which may stop other users to test it .

Remote debugging Java web app running in Glassfish

I have a web application. It is currently deployed on a remote server in a Glassfish instance. Is it possible to remotely connect to the server and debug the application (like I would a normal java application) using Netbeans?
If someone has done this and could provide insight or could point me to a guide, that would be great.
I know this functionality exists with Visual Studio and ASP.Net. I was not sure if there is a java equivalent.
Most examples that I have seen online are for applications that are simply running on a remote machine or for debugging a Glassfish application running on the local machine.
Yes, it is possible.
Once you have GlassFish running in debug mode, go to the Debug menu in NetBeans and click on Attach Debugger..., which brings up the Attach dialog. You'll probably go with something like:
Debugger: Java Debugger (JPDA)
Connector: SocketAttach
Transport: dt_socket
Host: hostname_or_ip_address
Port: 9009
Timeout may be left blank. When you click OK on this dialog, you should be able to connect your NetBeans debugger to GlassFish.
Remember:
The firewall on your remote server (and any gateways in between) should allow connections to the debugger port (9009 in my example).
Make sure you're using matching port numbers. In the GlassFish admin console, usually at: http://localhost:4848
Expand Configurations.
Expand server-config (or whichever you are using).
Click JVM Settings.
Check Debug to Enabled.
Verify that Debug Options contains:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
Read the JPDA docs for other options you can use.

Remote Debugging in eclipse

I have an application running in server A. The dev environment is in server B.
I am trying to do remote debugging of app running in server A.
In server A i added following command to service start script
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4554,server=y,suspend=n
And service is running in server A.
When i try to launch remote debugging configuration it gives
Failed to connect to remote VM. Connection refused. Connection refused
port 4554 is free in server A.
What other configuration need to be done for this?
Regards
Dheeraj Joshi
Try this.
Set suspend=y, just to make sure you got the JVM line right. This should stop the VM on startup until you connect.
If you're on Unix, bring up the terminal and try telnet [host] [port] - this will quickly let you know if there's anything listening to that port on that host.
Make sure the connection properties in Eclipse are set correctly. Note that the port defaults to 8000.
Use the IP address instead of the host name, to rule out DNS/hostfile problems.
Another way of starting the JVM that I use successfully is:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y
Check if there is a firewall between and/or on the two servers.

Categories