How to enter debug mode in eclipse when launching tomcat from cmd - eclipse

I am using apache-tomcat-8.5.24 and have the workspace in Eclipse configured and tomcat working properly.
I need though to do some debugging, but I dont know how can I enter debug mode in Eclipse with the tomcat running from cmd? I have done it several times in the past but I was always launching tomcat in debug mode from my IDE.

You would have to enable remote debugging on tomcat for which the following catalina property needs to be added in tomcat startup.sh or tomcat.start.sh or wherever you add tomcat startup properties:
CATALINA_OPTS="$CATALINA_OPTS
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
Then restart tomcat.
After this is done, you need to open eclipse, and to go "Debug --> Debug Configurations -- type in the search box "remote java application", and create new, then select your module/java project which you want to debug and give the port number same as given in the above command (i.e. 8787 in the example above). Then Apply and launch.

While the other answer may solve someones problem, it didnt solve mine. Though the way i followed and solved my problem is:
First you start tomcat (all services up), and then you start the debug mode in eclipse!!!
For tomcat as i use the catalina.bat jpda run to start my tomcat i just edited it and used it as follows:
catalina.bat jpda run - agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
For eclipse:
1)In Eclipse’s menu, select Run > Debug Configurations…
2)A new Debug Configurations window will appear
3)In the list on the left, select Remote Java Application. Don’t worry
too much about the word “remote” here. It just means that the JVM
process can either be on the local machine or another machine across
the network.
4)Select New in the context menu (you can either right click to see
the option for it, or select the icon above the list)
5)A new Remote Java Application debug configuration window will appear
6)Change the Name field to say “Tomcat (local)”, or the name of your
web application, your choice. The name you put here can be anything,
but shorter is better because the name will show up in menus.
Eclipse Run Configuration for a separate Tomcat JVM
There are at least three subtabs of configuration: Connect, Source,
and Common. Under the Connect subtab, there is a Project field. Select
the Eclipse project that represents the code you want to debug. For
instance, if you want to debug your webapp, select your webapp’s
Eclipse project here.
All of the other default settings should be fine. You should probably
look through the settings to see if you would like to change any
options, just beware of changing settings if you aren’t sure what the
effect will be. Make sure that the port number you’re setting in the
Connect subtab is the same port number you configured your Tomcat
JVM’s debug server to listen on.
Click Apply, then click Debug. At that point, your Eclipse’s debugger
will connect to your Tomcat JVM’s debug server. Next, switch to the
Eclipse Debug perspective. In Eclipse’s menu, select Window > Open
Perspective > Debug.

Related

Breakpoints not working in eclipse [duplicate]

I want to debug a webapp through Eclipse. The webapp will be running on a Tomcat 7 instance that I have configured within Eclipse, and thus everything, including Tomcat's launch will be done from within Eclipse.
Now, my question is what is the best way to debug the webapp in such a situation. Is local debugging possible, or the only solution is remote debugging.
I know how to do remote debugging, but given that everything is done from within Eclipse, I wanted to see if there is a better way of doing it.
Click on Run -> Debug Configurations.... On the left side you should have your tomcat server listed. (if not, you first have to define it in the preferences).
Configure your VM settings and whatever you need, then just click Debugin the lower right corner.
Your server should now start in debug mode, and stop on breakpoints.
From now on the server will be included in popdown menu of the Debug-Button in your toolbar.
Alternatively you can add the Servers View (Window -> Show View -> Servers), select your server and start it in debug by right-clicking

Remote debug JBoss AS 7.1 from Eclipse Indigo

I read some guides on the subject and made the following steps.
http://oreilly.com/pub/a/java/archive/eclipse-jboss-remote-debug.html?page=8
https://community.jboss.org/thread/177687
JBoss debugging in Eclipse
The guides have some distinctions but on the whole they are similar.
The steps I made.
I compiled and deployed my web project and deployed it on JBoss AS
7.1 by clicking Run on Server -> JBoss AS 7.1 in Eclipse.
I stopped JBoss AS in Eclipse.
I uncommented the line
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
in the $JBOSS_HOME/bin/standalone.conf file
I executed $JBOSS_HOME/bin/standalone.sh
I updated the page localhost:8080/MyProject/ in the browser and it
worked
I executed Debug -> Debug Configurations in Eclipse, then I created
a new configuration with the localhost as the host, 8787 as the
port, and MyProject as the project name.
I pressed the Debug button in Eclipse.
When I reach a breakpoint I added, nothing happens.
I expected that Eclipse would stop at the breakpoint as it does in a simple Java application project. What did I do wrong?
Eclipse version: Indigo.
Java.
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
Edit #1.
Window -> Preferences -> Java -> Installed JRE's
Edit JRE being used
Edit 'Default VM Arguments' line
-XX:+UseParallelGC
It didn't help.
Instead of making the changes in "standalone.conf", make the change in "standalone.conf.bat" .
Remove the rem from the line "rem set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"" .
This has worked for me.
You will need to start JBoss with a few extra options to the JVM. You can set these either in standalone.xml, or via the JAVA_OPTS environment variable. The options look basically the same, but for this post I will use JAVA_OPTS. Read this post from the JBoss Community forum if you want to use standalone.xml to configure the JVM parameters.
Add this line to your existing JAVA_OPTS:
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
The port number (8787) above must match your Eclipse setup (see below).
Finally, you will need to tell Eclipse how to connect to the remote process. In Eclipse, click the Debug button’s drop-down arrow and select “Debug Configurations”.
In that dialog, navigate to “Remote Java Application” and click the “New” button.
Under “Project” select the project that contains the code you want to debug.
Under Connection Type make sure “Standard (Socket Attach)” is selected.
Under Connection Properties, make sure the host (e.g., localhost) and port (which must match the port spec in the JAVA_OPTS, in this case 8787) are set.
Click on the “Source” tab and add any projects containing code you want to debug (if there are other projects in your workspace that contain code other than the main project).
In the Common tab, under “Display in favorites menu” select the Debug icon and a handy dandy icon will appear in your Debug toolbar dropdown (the name will be the same as the Project setting from earlier).
If JBoss is already running (with the options set earlier) click Debug to attach. If not, start JBoss, then click Debug to attach.
Now you can set breakpoints, step through your code, etc.
Have fun!

Debugging Webapps in Eclipse

I want to debug a webapp through Eclipse. The webapp will be running on a Tomcat 7 instance that I have configured within Eclipse, and thus everything, including Tomcat's launch will be done from within Eclipse.
Now, my question is what is the best way to debug the webapp in such a situation. Is local debugging possible, or the only solution is remote debugging.
I know how to do remote debugging, but given that everything is done from within Eclipse, I wanted to see if there is a better way of doing it.
Click on Run -> Debug Configurations.... On the left side you should have your tomcat server listed. (if not, you first have to define it in the preferences).
Configure your VM settings and whatever you need, then just click Debugin the lower right corner.
Your server should now start in debug mode, and stop on breakpoints.
From now on the server will be included in popdown menu of the Debug-Button in your toolbar.
Alternatively you can add the Servers View (Window -> Show View -> Servers), select your server and start it in debug by right-clicking

eclipse debug remote web application

I have a struts2 web application developed in eclipse IDE and exported
it as war file and deployed it in tomcat7 installed in windows server.
Now I need to debug this deployed web application in eclipse inside my local system.
How to bring those codes inside?
I found some links but I stuck with how to bring those code into
eclipse in my local system to place break points.
these are those few links...
link 1 link 2 link 3 link 4
..Or simply navigate to the bin folder and start your tomcat with the following command:
catalina jpda start
No need to make any changes with this approach.
The defaults are the same as quoted by Ingemar: port 8000 and transport=dt_socket.
Confirmed to work with tomcat 7 (.0.40 or newer to be precise).
Then follow his instructions and setup a Remote Java Application debug configuration in Eclipse. Basically, just use the defaults - they match (at least in Juno and Kepler). You might want to check the Source tab or do this on demand while you debug.
... Or, in case you use maven, you might consider the tomcat7-maven-plugin plugin, which will completely keep you inside eclipse.
Happy debugging
Solution for windows:
First you have to modyfy your tomcat startup script (startup.bat):
Put this on top of the startup.bat
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
...
Then modyfy the following line (nearly at hte end of startup.bat):
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
to
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Now you can start tomcat by executing startup.bat and tomcat opens the port 8000 for debuging.
Second step is to configure Eclipse:
Select Run > Debug Configurations ...
Create a new configuration by selecting 'Remote Java Application' with a right click.
Check that the right Project is selected.
And modyfy the Connection properties. (Note that the port has to be same (8000) as entered in startup.bat and not the port on which your struts app is running)
Finaly you have to click on Debug
Now you should be able to set breakpoints.

HTTP Status 404 - The requested resource (/) is not available

I integrated Tomcat 7 in Eclipse. When I start it using Eclipse, it shows that Tomcat is up and running, but when I go to http://localhost:8080 in my browser, it gives me following error:
HTTP Status 404 - /
type Status report
message /
description The requested resource (/) is not available.
Apache Tomcat/7.0.23
I tried changing the port in server.xml just in case if 8080 is used by another service, but it didn't work either. How can I solve it?
What are you expecting? The default Tomcat homepage? If so, you'll need to configure Eclipse to take control over from Tomcat.
Doubleclick the Tomcat server entry in the Servers tab, you'll get the server configuration. At the left column, under Server Locations, select Use Tomcat installation (note, when it is grayed out, read the section leading text! ;) ). This way Eclipse will take full control over Tomcat, this way you'll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse. I only don't see how that's useful while developing using Eclipse.
The port number is not the problem. You would otherwise have gotten an exception in Tomcat's startup log and the browser would show a browser-specific "Connection timed out" error page (and thus not a Tomcat-specific error page which would impossibly be served when Tomcat was not up and running!)
Following steps helped me solve the issue.
In the eclipse right click on server and click on properties.
If Location is set workspace/metadata click on switch location and
so that it refers to /servers/tomcatv7server at localhost.server
Save and close
Next double click on server
Under server locations mostly it would be selected as
use workspace metadata Instead, select use tomcat installation
Save changes
Restart server and verify localhost:8080 works.
Copy the ROOT (Default) Web App into Eclipse.
Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.
Go to C:\apache-tomcat-7.0.27\webapps, R-click on the ROOT folder and copy it.
Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps". You should find something like your-eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse).
Go to the wtpwebapps folder, right-click, and paste ROOT (say "yes" if asked if you want to merge/replace folders/files).
Then reload localhost:8080 to see the Tomcat welcome page.
I did what BalusC said but it was not enough for me, I had to clean the Tomcat workdirectory : ( Click right on right on Tomcat in the Servers Tab -> Clean Tomcat Work Directory )
Please check in your server specification again, if you have changed your port number to something else.
And change the port number in your link whatever new port number it is.
Also check whether your server is running properly before you try accessing your localhost.
If you are new in JSP/Tomcat don't modify tomcat's xml files.
I assume you have already deployed web application. But to be sure, try these steps:
- right click on your web application
- select Run As / Run on Server, choose your Tomcat 7
These steps will deploy and run in the browser your application. Another idea to check if your Tomcat works correctly is to find path where tomcat exists (in eclipse plugin), and copy some working WAR file to webapps (not to wtpwebapps), and then try to run the app.
If options under Server Locations are grayed out, note the message in the section title: "Server must be published with no modules present". To publish the server, right click the name of the server in the Server window and select "Publish".
Sometimes cleaning the server works. It worked for me many times.This is only applicable if the program worked earlier but suddenly it stops working.
Steps:
" Right click on Tomcat Server -> Clean. Then restart the server."
I had the same problem with my localhost project using Eclipse Luna, Maven and Tomcat - the Tomcat homepage would appear fine, however my project would get the 404 error.
After trying many suggested solutions (updating spring .jar file, changing properties of the Tomcat server, add/remove project, change JRE from 1.6 to 7 etc) which did not fix the issue, what worked for me was to just Refresh my project. It seems Eclipse does not automatically refresh the project after a (Maven) build. In Eclipse 3.3.1 there was a 'Refresh Automatically' option under Preferences > General > Workspace however that option doesn't look to be in Luna.
Maven clean-install on the project.
** Right-click the project and select 'Refresh'. **
Right-click the Eclipse Tomcat server and select 'Clean'.
Right-click > Publish and then start the Tomcat server.
In my case, I've had to click on my project, then go to File > Properties > *servlet name* and click Restart servlet.
For me, my Eclipse installation was hosed - I think because I'd installed struts. After trying a dozen remedies for this error, I re-installed Eclipse, made a new workspace and it was OK. Using Kepler-64-Windows, Tomcat 7, Windows 7.
This worked for me:
Project > Build Automatically (Make sure it's turned on)
Project > Clean ...
Right click Tomcat > Properties > General Tab > Switch Location (switch from workspace metadata to Server at localhost.server)
Restart Eclipse
Run Project As Server
Apache Tomcat/7.0.23 service is not loaded or enabled. Pls check the service status and other app which is using 8080 port currently. To check this use netstat command and observe whether another app is occupying the port 8080!