Can't debug servlet Eclipse + Glassfish - java

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?

Related

How to debug dynamic web page in Eclipse?

I am trying to debug my dynamic web application in Eclipse (Helios) as Debug mode but it could not work out. I have googled eventually i confirmed that i have to do Remote Debug. I trying to do Remote Debug. It seems doesn't work. Could please any one help me out to how to do set up Remote Debug and please mention steps to setup.
What app. server (web container) are you using ? I.e. tomcat , Add that server to your eclipse using "add server" and add project to it then run server in debug mode.
Sometimes its an issue with port.The port which you are trying to access is already occupied and wouldn't be released and you get this exception.Try restarting your system,in my case it worked.See the below post for more troubleshooting.
See Also
Eclipse : Failed to connect to remote VM. Connection refused.

Tomcat debugging not possible through eclipse

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.

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 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.

Can't debug using eclipse and weblogic 8.1 ( weblogic 10 works fine)

first of all, Is it possible to debug web apps with eclipse and weblogic 8.1.
I can successfully debug with weblogic 10.
in weblogic 8.1 when I click on debug server from eclipse it shows me a debugging warning about debugging jsp pages. and then starts. when It start, the server state shows in eclipse as "started" not debug compared to weblogic 10 and break points dont work at all.
I did set up my startWLS.cmd file correctly for debugging.
I m using eclipse 3.4
I believe you are using some kind of plugin to eclipse that allows you to debug code running on weblogic without being notified about the gory details of the process.
Actually what happens is that your are running weblogic as external process (even if you see its stdout into the eclipse console) and connect to it with remote debugger.
So, probably your plugin does not support weblogic 8.
But it is very simple to debug any java application remotely.
The following article describes how to do this: http://eclipse.dzone.com/articles/how-debug-remote-java-applicat
Shortly you have to add the following options when your run your application:
-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y
Just find the bat/cmd/sh script that runs weblogic and modify it.
Then start remote debugging by Run/Debug Configurations/Remote Java Application
and configure the port your specified when your ran your application.
Stack Overflow is cool site, but you will likely get more on-topic responses to your question by asking it on Oracle's eclipse tooling forum:
http://forums.oracle.com/forums/forum.jspa?forumID=578

Categories