jboss not starting in debug mode with breakpoints - java

my local jboss server is starting in normal mode, and I am able to access my application. I wanted to debug my java web application , so I put the breakpoints and tried to start the server in debug mode. but it is unable to start server in debug mode. then I removed all my breakpoints ,now my server is starting in debug mode. but now I can't see step into & step out buttons enabled( I think as there is no breakpoints set). my goal is to get understatnd the the process flow for a particular request. can anybody help me out in this ,if I am doing something wrong

How did you start it in debug mode?
Perhaps is something like this:
set JPDA_ADDRESS=8001
set JPDA_TRANSPORT=dt_socket
Maybe with export instead of set if you are in Unix env. The second part is listening to that port from wherever you have your code. Eclipse? Netbeans? Set a debug configuration (Remote Java Application listening in the defined port, in case you use Eclipse) and start the debug configuration. Now your IDE will show you when execution reaches your breakpoint.

Related

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

debug java application while startup

It might sound a bit too naive, but I always had a tough time to debug a java class during server startup. Here is the scenario:
The java application is hosted on a tomcat server.
Suppose there is a class which is invoked while the tomcat server starts up.
As soon as I stop the tomcat instance for a restart, the eclipse debug stops and I can start the debug only once the application is up and running.
Now how do I debug this class on eclipse?
Thanks for you help in advance.
You need to pass the "wait for debugger to connect" flag to tomcat. So the startup will wait until you have connected and thus you won't miss the breakpoint.
Take for example those java options to make tomcat listen for a debugger:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8797,server=y,suspend=y
The wait for a debugger connection flag is the suspend=y entry in the above line.
Debugging of classes during startup should work without problems. For example, suppose you implement a ServletContextListener class. The belonging contextInitialized method is called during Tomcat startup (or to be more precise: while your app gets deployed).
You can set breakpoints in this class. At that point, Tomcat is already started completely and there shouldn't be any problems with debugging.

IntelliJ IDEA debugger follow child process

We have some Java code that starts a new process using the following code: Runtime.getRuntime().exec(command); I'd like to be able to tell the debugger that it should follow the child process like you can do with GDB as documented here by issuing the set follow-fork-mode child command.
Is there something equivalent in the IntelliJ IDEA Java debugger? If so how do I configure it?
Thanks
Java doesn't provide an automated way to debug processes and their child processes. One needs to run the child process with the JVM options to enable debugging. IDEA Remote Debug configuration will suggest the proper options to use. Once the process is started with the appropriate options you can connect to it from IDEA with the Remote Debug configuration.
Sample options:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
You may want to start with suspend=y so that the execution is suspended until you connect with the debugger.
We now have this Intellij plugin that uses a java agent to automatically start all child processes in debug mode.
It listens for any debugee processes on 7857, then attaching debugger to those processes.
Install AttachMe
To enable automatic mode, run this first, source ~/.attachme/conf.sh
Afterwards start AttachMe listener
Test it with maybe a Play application in prod mode (assuming play plugin is enabled), do sbt start. Play in prod mode forks another JVM process. Debug points should now hit.

Can't debug servlet Eclipse + Glassfish

The server is in debugging mode. I've set 10 breakpoints and the browser just skips them all. Why? This happens with JSPs also in that project. Why?
Have you checked that the Debbuger is indeed connected with Glassfish? Also please note that it is not possible for the debugger to stop at breakpoints which have been set inside jsp. AFAIK, debugger works only pure java code
So you are connecting to external server with "debug remote java application".
What is your server's debug port? Port 8000 is default setting in eclipse debug configuration for remote java appilcation. You should change that value to one that GlassFish server is configured for debugging.
Also, take a look at How do I debug GlassFish 3 using Eclipse Helios?

Is there a way to force Eclipse to automatically restart remote debugging (in listen mode)?

I'm using Eclipse to remote debug an application that's in debug client-mode (i.e -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000 jvm startup parameters, and Eclipse has "socket listen" mode selected in the debugger settings instead of the default "socket attach" mode).
Problem is, once the remote application is started, connects to the Eclipse debugger, and finally exits... the Eclipse debugger stops listening for connections on the specified port.
Just an annoyance, but it'd be nice not to have to keep clicking on the debug button in Eclipse every time I need to debug the application (which needs to be started from outside of Eclipse obviously). Any ideas or tools out there for making this a little more automatic?
By the nature of the client mode debugging, you will possibly relaunch eclipse in debug mode (listen) manually because you will do the same with the client application (attaching it to the eclipse listening port using jdwp).
But you also can try create a launch configuration programatically using Eclipse SDK, implementing an algorithm to restart the "listen mode" when the vm exists.
Just a thought , Can you try using:
-Xrunjdwp:transport=dt_socket,server=y,**suspend=y**
Your application will be suspended till the time the debugger is attached, that way you would atleast be able to debug right from the entry point to your code.

Categories