How to debug a JSP tomcat service using eclipse? - java

I would like to debug my separately running JSP/Struts/Tomcat/Hibernate application stack using the Eclipse IDE debugger. How do I setup the java JVM and eclipse so that I can set breakpoints, monitor variable values, and see the code that is currently executing?

I just Googled it. :)
http://bugs.sakaiproject.org/confluence/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging
Many more on google.
Effectively, set your JPDA settings:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start
Then, in Eclipse, Run->Debug Configurations...->Remote Applications.

Follow these steps:
Add the following arguments to the java command that is used to launch Tomcat (on Windows, I think this is in TOMCAT\bin\catalina.bat)
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
In Eclipse, create a 'Remote Java Application' debug configuration and set the port to 8787 and the host to the name (or IP address) of the machine where Tomcat is running. If Tomcat is running on the same machine as Eclipse, use 'localhost'.
In the 'source' tab of the debug configuration, add any projects that you want to debug into
Start Tomcat
Launch the debug configuration you created in step 2
Eclipse should now stop at any breakpoints that you've set in the projects you added in step 3.
Notes:
You can change the port to any other available port if for some reason you can't use 8787
If you want Tomcat to wait for the remote debugger to start, use 'suspend=n' in the command above to 'suspend=y'

You could do what they suggest, or use this Eclipse plugin, which makes it easier to configure Tomcat to begin with: Eclipse Tomcat Plugin
When launching tomcat via this plugin, it starts in debug mode by default, you must explicitly disable debugging mode if you want it to not allow Eclipse to connect a remote debugger.

For Tomcat 5.5 on Windows:
Edit bin/startup.bat
Find the line that reads:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
Replace it with these lines:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Related

Error during starting tomcat in remote debug mode

Tomcat is not starting in debug mode. Getting below logs.
C:\ApacheSoft\apache-tomcat-7.0.67\bin>catalina.bat jpda start
Using CATALINA_BASE: "C:\ApacheSoft\apache-tomcat-7.0.67"
Using CATALINA_HOME: "C:\ApacheSoft\apache-tomcat-7.0.67"
Using CATALINA_TMPDIR: "C:\ApacheSoft\apache-tomcat-7.0.67\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.7.0_79"
Using CLASSPATH: "C:\ApacheSoft\apache-tomcat-7.0.67\bin\bootstrap.jar;C:\ApacheSoft\apache-tomcat-7.0.67\bin\tomcat-juli.jar"
=transport=dt_socket was unexpected at this time.
Let me guess, you read a link called "HOW TO REMOTELY DEBUG APPLICATION RUNNING ON TOMCAT FROM WITHIN INTELLIJ IDEA" on blog.trifork.com.
The instructions say to do this for Windows in your setenv.bat:
set JPDA_OPTS="-agentlib:jdwp=transport=dt_socket, address=1043, server=y, suspend=n"
Yeah, that's not going to work. catalina.bat adds its own quotes, so it winds up trying to do this:
if not ""-agentlib:jdwp=transport=dt_socket, address=1043, server=y, suspend=n"" == "" goto gotJpdaOpts
A better plan is to do this:
set JPDA_OPTS=-agentlib:jdwp=transport=dt_socket,address=1043,server=y,suspend=n
I know this is from almost a year ago, but I ran into this, and ultimately had to remove "#echo off" from the Tomcat batch files and chase this down myself. Hopefully, this will get voted up so that it can save someone else this grief.
There is another possibility that you configure both two different ways to enable JPDA in jvm during starting tomcat in remote debug mode.
In windows, there're several ways to enable JPDA in jvm.
1.one way is :
open the startup.bat.
add the lines below
set JPDA_ADDRESS=8001
set JPDA_TRANSPORT=dt_socket
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
2.the second way is:
create a setenv.bat file under CATALINA_HOME/bin directory.
and add the line below:
set JPDA_OPTS=-agentlib:jdwp=transport=dt_socket, address=1043, server=y, suspend=n
of course, they're other ways.
I have the same problem with you, but then I found I configured in these ways both, it will result in the failure to open the JPDA port, without any error details.
Then I chose the method 1 only, the port was opened successfully.
Hope this can help other newbies on this.
The space char in C:\Program Files\Java\jdk1.7.0_79 cause the problem.
Replace it with short name could solve the problem.
Execute command dir c:\PROGRA~1\Java\jdk1.7.0_79 and check the file list to verify whether PROGRA~1 is correct. If not, try PROGRA~2 and so on...
Then change environment variable JAVA_HOME or JRE_HOME to try again.

Debug remote java application using Intellij

I am trying to debug remote java application in Intellij but unable to get sucess, The steps which I am doing is
Run>Edit Configuration> Defaults> Remote
What is/are I am missing?
First, create a new Remote debugging configuration:
ALT + U + R
Take note of the port which IntelliJ plans to listen in Tomcat. On my setup the port is 8000, which is the default and this should be fine for your setup as well. To change the Tomcat JPDA port, edit catalina.bat (or whatever your startup script is) and find a line which looks like the following:
set JPDA_ADDRESS=8000
Second, make sure that you are building your project with javac -g .... The -g option means that debugging information will be turned on in your Spring WAR.
Finally, when you start Tomcat, use catalina jpda start, which will tell Tomcat to connect the debugger to port 8000. When you want to connect to IntelliJ then use ALT + SHIFT + F9 and select your remote configuration from the menu. Of course, you should add some breakpoints, without which it doesn't make much sense to be in debug mode.
You don't need to edit the defaults. You need to use the [+] button to create a new Remote run configuration and specify its settings.

Debugging with Eclipse - Tomcat server window disappears on initiating Debug in Eclispe

I am trying to remote debug my application. This is what i have done till now.
1 - environment variable set - JPDA_TRANSPORT=dt_socket
2 - environment variable set - JPDA_ADDRESS=4000
3 - In startup.bat file, the following line
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
is replaced with
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
4 - in the setenv.bat file, the following line has been added
set "CATALINA_OPTS=%CATALINA_OPTS% -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000, suspend=n"
In Eclipse, In debug configuration window, I set the port to 4000, pointed the source. Restarted the eclipse.
Behavior
When is start the Tomcat, the Only following line is printed on the server console, nothing else.
*Listening for transport dt_socket at address: 4000*
When i go into Eclipse, do in debug configuration and press debug , the tomcat(server) window disappears. I have no logs and no clue what is happening.
Note
I am using windows 8.1 , Eclipse Luna, Java 7
Any help will be highly appreciated.
Add this line in catalina.bat
set JPDA_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9876
in the end of startup.bat make sure jpda is present startup.bat file
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Java plugin does not attach to debug session in Eclipse

this functionality used to work and now it seems broken, I a do not know how to diagnose it.
I am developing a java Applet that runs in a browser. I used to set up the runtime parameters in the java console to (Windows platform):
-Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=n,suspend=n
This setting appears both in the User and System tabs in the Java console.
Then I would start a debug session in eclipse for my applet project and set it to listen on port 8000. When I launch the browser and the applet is loaded, it would attach to eclipse and I was able to debug and set breakpoints, etc.
Now, it seems that this is no longer happening. When I launch the debug session in Eclipse, I do see port in LISTENING mode and owned by javaw.exe, which is correct. The only problem is that when the browser loads the Java plugin, it does not honor the "Runtime Parameters" and does not connect to the listening debug session in eclipse.
I have the latest Java update installed.
What else should I be looking into?
I just resolved my issue.
I edited:
C:\users\\AppData\LocalLow\Sun\Java\Deployment\deployment.properties
and added the pararameters as follows:
deployment.javaws.jre.0.args=-Djava.compiler\=NONE -Xnoagent -Xdebug -Xrunjdwp\:transport\=dt_socket,address\=8000,server\=n,suspend\=n
When i added the runtime parameters through the UI, they went to
"deployment.javaws.jre.1.args" so I duplicated them into "deployment.javaws.jre.0.args"

debugging java application deployed in tomcat

I have an application that I deployed in tomcat. Later I configured the code as a project in Eclipse. I want to connect to the tomcat via eclipse and debug the application.
Trying to setup a remote debug connection is throwing up errors. Is there any entry that I need to add somewhere in tomcat?
First, you need to run Tomcat in debugging mode. The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not). Find the line near or at the end of the file that contains the start command, and change it to jpda start. This will cause Tomcat to start in debugging mode listening on port 8000.
Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations.... In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list. The important settings to note are the Host and Port fields. The host value must match the hostname of the Tomcat process, and the port should be 8000. You also might need to add entries on the Source tab to ensure that all of the source code is available to step through.
Create a new tomcat server
Create a new dynamic web project
Export war to tomcat server
Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)"
Add breakpoints
Run tomcat in debug mode
Test war in web browser
Edit source path
Debug source code in Tomcat
The war file is available here.
yes, you need to configure tomcat to accept remote debugging connections. There is a FAQ on how to do it with various IDEs.
http://wiki.apache.org/tomcat/FAQ/Developing#Q2
Simply change the line in startup.bat (if you are using Windows)
from:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
to:
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Right Click on the project you want to debug and go to Debug As Menu and in the list click on Debug Configurations.
Then Double click on the Remote Java Application from left menu list. browse for the project u wanna add in then click apply.
Also change the listening port to 7999, then after you started the web app from your localhost click the debug button on the same window. Then any break point's will be hit after that.
Steps to setup the tomcat Debugger with eclipse
Install the following things:
java 1.8+
eclipse EE version
download tomcat 8+
open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)
Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)
Export war (File-> Export-> search war -> select module and choose the path)
Run as -> Run on Server
Start the tomcat Server in Debug or Run Mode
check on localhost:8080
Debug worked for me. I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.
Open tomcat/conf/bin/startup.sh and added below lines
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
In the same file startup.sh, added jpda before start command.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$#"
Restart the tomcat.
In eclipse go to Run>Debug configuration>Remote java application>Add host ip and port(8000) where tomcat is running.
In my case i required to open 8000 through firewall too.
firewall-cmd --zone=public --permanent --add-port=8000/tcp
firewall-cmd --reload
Beside remote debugging, you can debug your app locally within eclipse if you added tomcat in eclipse.
just start server and wright click your app and from debug menu hit debug on server.
If you have multi module maven project, debug on server just shown up for module with war packaging.
If you want debug a class that runs at startup by self, like methods that annotated with #PostConstruct, remember that you should increase server timeout.
To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.

Categories