How do i debug a web application running on jetty in eclipse? - 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

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!

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.

Debug Solr code in Eclipse

New to Eclipse and Solr, I imported apache-solr-3.6.0.war into Eclipse and run Solr with tomcat plugin. Now i want to debug some existing code, however how do i import the Solr source code?
Without knowing how you imported it exactly: sounds like you are looking for Source attachment.
It might be better if you use the Solr source code directly. Check the README file included in the release, there is an ant task to init eclipse:
To setup your ide run [...] 'ant eclipse'.
Then all dependencies are loaded using ivy and you can run it from within the IDE.
You can also check out the whole Lucene/Solr source:
install Subclipse add-in
choose New... > Project...
SVN > Checkout projects from SVN...
add this link as new repository
select branch /branches/lucene_solr_3_6 (if you want last stable version. Use trunk if you want to use cutting edge source)
choose Check out as a project in a workspace and leave everything else default
Then, after the checkout completes, to complete setup, you don't have to fiddle with JARs manually, simply:
right click on main build.xml, the one in your project's root
choose Run As... > Ant build... select (in this order)
ivy-bootstrap and resolve tasks (which will download all JAR dependencies)
then run in this order: validate, clean-idea, eclipse, compile, get-maven-poms, generate-maven-artifacts (the last two only if you plan to use Maven).
And that's it, you should now see no redness in your workspace and have Lucene and Solr JARs built.
Run solr like this:
java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 start.jar
Solr will start, but wait you to connect from Eclipse to continue.
Then in Eclipse, go to:
Run / Debug Configurations...
Select Remote Java Application
Press New button to create a new remote configuration
put 1044 on port
Click on Debug
This is the standard way to debug remote applications in Java
./solr start -p 8983 -f -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=0.0.0.0:8000"
Start solr with
provide app run on port 8983
provide Xrunjdwp:transport=dt_socket
remote ip address 0.0.0.0:8000
and then go to eclipse

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.