eclipse debug remote web application - eclipse

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.

Related

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

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.

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!

How do i debug a web application running on jetty in eclipse?

never done web programming before. Is there a way to set breakpoints, see variable values in eclipse? The app i want to debug makes a Query string whcih i would like to easily extract.
Click External Tools Config,
Select program and click the new button top left.
Set location to your maven binary
working directory to local workspace and arguments to jetty:run
In the environment tab set the maven opts. Notice socket address = 4000 and suspend=y
The go to debug configurations and add a new remote application. Add a project name and set the socket address. Now run the External tool it should say:
Listening for transport dt_socket at address: 4000
Then you can debug the remote app and add breakpoints etc.
I would run the application with maven using the command: mvnDebug jetty:run
And setup a remote Java application using port 8000, in Eclipse IDE.
See the 'Setting up Maven 2.0.8+' section of: http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE
None of the answers worked for me. Here's what did work:
Create Maven Eclipse Runtime for your project:
right-click on project -> maven build -> goals: jetty:run
go to JRE tab of your Maven Eclipse Runtime, and in the VM arguments section add:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
When you execute this runtime, the first thing the Eclipse console outputs (in blue) is:
Listening for transport dt_socket at address: 8000
Now you can create a Remote Java application Debug Runtime and connect to the debug port (8000 in this example)
I would just expand eaykin's answer as the URL is broken.
Run the Mvn Debug as bellow...
$ mvnDebug -Dmaven.test.skip -Denvironment=dev clean jetty:run
This will wait on port 8000
Preparing to Execute Maven in Debug Mode Listening for transport
dt_socket at address: 8000
Then go to the Eclipse Run --> Debug Configurations --> Remote Java Applications
Define Host as 'localhost' and port as 8000 if they are not default.
If you click on the "Debug" button, this will start the application from mvn.
"Trying to run it this way i get CreateProcess error=193, %1 is not a valid Win32 application."
On windows select mvn.bat instead of mvn.exe.
If by any chance you are using intellij. It is way easier.
Make sure you have jetty plugin installed. Then
In the Maven Tab on the extreme right, expand your project
Expand Plugins
Expand jetty
Right click on jetty:run and select 'Debug DEBUG'Click to see the screenshot for refence
The answer for this post shows you the flags need to pass to the JVM for a remote debugger to attach.
Remote debug Jetty (no mvn, no plugins)
This is the page that explains remote debuggers for the JVM
http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/jdb.html

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!

Debug Playframework in Eclipse

I just moved from Netbeans to Eclipse. In Netbeans, I can debug Playframework applications out of the box. However, in Eclipse, it seems hard to configure this in order to debug a web app (a Playframework app in specific).
As in Play! documentation,
The main launcher in only usable with the Run As eclipse command. You
can then use the “Connect JPDA launcher” using “Debug As” to start a
debugging session at any time. Stopping the debugging session will not
stop the server.
However, I can not see “Connect JPDA launcher” in "Debug As" (I'm using Eclipse Classic 3.7.0).
I've searched about JPDA (I'm new to Java and don't know about "main launcher" and JPDA, then config Remote Debug as instruct in
http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html
But it's returning an error:
Failed to connect to remote VM. Connection refused. Connection
refused: connect
I've searched and found some suggestions like:
1.)editing catalina.bat and adding the lines : set
JPDA_TRANSPORT=dt_socket ... set JPDA_ADDRESS=8000 AND
2.)Editing startup.bat call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Actually I don't clearly understand this and I guess it's for configuring Tomcat. However, I'm using Play! default server, checked the application.conf and sure that it's listening to port 9000 and 8000 for JPDA.
Of course, I have started the Play app before debugging, I can access the app via port 9000 normally. I'm using Win 7 with no admin rights.
Do you have a detailed guide on debugging Play! in Eclipse?
As of Play 2.0, the eclipse folder and launchers are no longer generated when you run play eclipsify. After running play eclipsify, you can debug your project in Eclipse as follows:
In a console outside of eclipse, run play debug run.
In Eclipse, right-click your project, then choose Debug As -> Debug Configurations...
Right-click Remote Java Application, then click New.
The host should already be set to localhost. Set the port to 9999 (the default port used by the play debug run command).
Click Apply to save, then Debug to connect to your running Play instance.
First of all, you have created the configuration files for Eclipse by using the play eclipsify YourProject command, right? (If not, see Play framework documentation for more information.)
After that, you should have a folder named eclipse in your project. In it, you should see commands Connect JDPA to YourProject.launch, YourProject.launch and Test YourProject.launch.
Right-click on the YourProject.launch and choose Run As --> YourProject from the pop-up menu. That will start your application. When the application is running, right-click on the Connect JDPA to YourProject.launch, and choose Debug As --> Connect JDPA to YourProject.launch from the pop-up menu. That will start a debug session on your application.
Play 2.1-RC2 : Running Play! app that is synced with Eclipse
To make the project Eclipse compatible, got he project folder and then give command
">play eclipse". Now you can add it as an existing project form eclipse.
Then to run it you have to first run start play in the project folder i.e. command "play"
This will activate play server and identify the app in the project i.e. [appname]$
now you have to just give the command "run" to see your app running on the localhost:9000 or whichever port config you have specified.
Debug mode: To run this similarly you need first give command "play" then [appname]$ "play debug run" this will by default use port 9999 so when you go to localhost:9000 in your browser and in your eclipse file -> Debug As -> Debug configuration.. -> New Remote Java Application -> connect specify port 9999 and debug
With activator, you'll need activator -jvm-debug <port number> ~run
I guess most of you are running the play framework with Typesafe Activator. If you are doing so, This may help you,
activator -jvm-debug ~run
Like : activator -jvm-debug 9999 ~run
(then It will start the debugger in 9999 port along with the app running in 9000 port.)
Now go to eclipse and right click on the project name you want to debug and select Debug As -> Debug configuration.. -> (select)Remote Java Application -> new (top left an icon with tiny plus sign) -> connect specify port 9999 and debug.
As of Play 2.1.2, I was getting the 'address in use' error when running play debug run.
The fix was to edit play.bat in play-2.1.2 directory and change these two lines:
:setDebug
set JPDA_PORT=9999
to
:setDebug
set JPDA_PORT=8551
Then in Eclipse, select Debug Configurations, find "Remote Java Application", do New. Then set port to 8551. Now you can start play using
play debug run
And then in Eclipse start debugging using the debug configuration you created about.
If you run "play eclipsify" on the project folder, it will create two run configurations.
Looking at the run configuration details, you should check if the following line (or something similar) is in the "VM arguments":
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Dplay.debug=yes
-Dplay.id=test -Dapplication.path="${project_loc:NMKServer}"
-Djava.endorsed.dirs="c:\Java\play-1.2.2/framework/endorsed"
-javaagent:"c:\Java\play-1.2.2/framework/play-1.2.2.jar"
Here you can configure the debugging port. With this config, I can attach to process using the instructuctions you have.