How do I Debug Java Application Server in Eclipse? - java

I am attempting to Debug a simple Java Server Application hosted on localhost on any given port. Within Eclipse I run it in debug mode to wait on an incoming connection. When I run my a browser to retrieve data from the server I get nothing. If I run the Application outside of Eclipse, everything is fine and my pages are served.
Is there anything I need to do in Eclipse to enable ports or anything?
I saw this post:
How does Eclipse debug code in an application server?
but that is only informational. Any help would be great.

To debug applications that run on another JVM or even on another machine, start them with these flags:
java -Xdebug -Xnoagent \
-Djava.compiler=NONE \
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
Enter the hostname and port to connect for debugging:
Run → Debug Configuration... menu
Create a new debug configuration of the Remote Java Application type.
This configuration allows you to enter the hostname and port for the connection.

Eclipse Settings:
1.Click the Run Button
2.Select the Debug Configurations
3.Select the “Remote Java Application”
4.New Configuration
a) Name : GatewayPortalProject
b) Project : GatewayPortal-portlet
c) Connection Type: Socket Attach
d) Connection Properties:
i) localhost ii) 8787
For JBoss:
1.Change the /path/toJboss/jboss-eap-6.1/bin/standalone.conf in your vm as follows:
Uncomment the following line by removing the #:
JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
For Tomcat :
In catalina.bat file :
Step 1:
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
Step 2:
JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
Step 3: Run Tomcat from command prompt like below:
catalina.sh jpda start
Then you need to set breakpoints in the Java classes you desire to debug.
Hope this helps.

Related

What is the most efficient/automated way to remote debug a SOA application running on Linux VM from Windows desktop through IntelliJ IDEA?

enter image description here
I want to build and remote debug an SOA based CDI java application running on a Linux VM from Windows desktop using IntelliJ Idea. What is the most efficient way to do this so that it relieves me from manually transferring (sftp) the application, set up for remote debugging, etc?
I don't want to exit my IDE but would like to debug the application on a remote machine by modifying the app repeatedly. I would like to see the results in the IDE console window/web browser as applicable.
I used the remote debugging option in Intellij IDE, In run/debug configuration option I used Listen to remote JVM and start the debug in IntellijIDE.
I then run the following command in VM Linux:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 com.intel.podm.rest.RequestValidationFilter
In Intellij IDE the command line arguments are dynamically updating to
-agentlib:jdwp=transport=dt_socket,server=n,address=DESKTOP-52V2CBR:5005,suspend=y,onthrow=,onuncaught=
This is fixed by opening SSH on Linux and remote debug in Intellij,and port number changes in standalone.sh script as project is based on wildfly server builded in gradle build environment.
Step 1: open a remote debug
step 2: ssh targetMachine#10.10.10.10 –L 8888:127.0.0.1:8787
If your application is in different machine try to create SSH tunnel for example:
ssh targetMachine#10.10.10.10 –L 8888:127.0.0.1:8787
Where targetMachine#10.10.10.10 is target user and address.
8888 is the local port where is IDE
8787 is debbuger port in the targetMachine (you can check that port in standalone.sh script)

How to enable remote debugging for an Eclipse Application?

Im trying to enable remote debugging for an eclipse plugin project, for the purpose of using IntelliJ IDEA as a debugger.
The steps I've taken so far:
Launch Eclipse.
Run -> Debug Configurations...
Create a new "Eclipse Application" (as to launch a local workspace which loads the plugin).
Add -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n to VM arguments.
Press the Debug button.
I get the following error:
ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Error occurred during initialization of VM
agent library failed to init: jdwp
What steps should I be taking to get IntelliJ IDEA to be able to debug an Eclipse Plugin running in a runtime workspace?
Run -> Debug Configurations...
Add -Xdebug -Xrunjdwp:transport= dt_socket,address=1044,server=y,suspend=n to VM arguments.
This is redundant. Using a debug configuration already starts the application with the eclipse debugger attached to the process. Start it as a run configuration instead if you want to enable debugging through a server socket.
You can then create an additional "remote java application" debug configuration to attach to that socket.
I would suggest you NOT try to launch the Eclipse app from within Eclipse.
Export the app to be a stand alone eclipse application.
Modify the eclipse.ini file and add the necessary debug parameters to the '-vmargs' entry.
Launch the stand alone app as you normally would.
Attach the development Eclipse instance to the test app as you would normally do for a remote debug.
Tomcat Configuration:->
By default remote debug happens at 8000 port.If you want to change this then go to catalina.bat file and update this line
set JPDA_ADDRESS=localhost:8000 to desired port no.
And you can also set this property in setenv.bat file. Generally this file is not there in tomcat so just create one batch file with name
setenv and write this line set JPDA_ADDRESS=localhost:8000.
Now go to bin directory then open command promt and write "catalina jpda start". It will make the tomcat run in debug mode. You can verify it
by seeing something like this "Listening for transport dt_socket at address: 8000"
1)Eclipse
Go to run->debug configuration->Remote Java Application->Click on new Launch configuration
And then fill the detials like project ,port(Give same port no as you have configured in tomcat), host(If you are using local you can give
local then apply and debug
I am using eclipse 2020.09 .
Eclipse remote debug img
2)Intellij Idea:
Go to Add configuration->click on +->and select remote jvm debug->Then give the same port no and name(any name) then apply.
Intellij Idea Remote Debug img

How to Start Jboss 5.1.0.GA in Debug Mode for Remote Debug in Intellij

I want to set up breakpoints and remote debugging for a Jboss application in Intellij. From this blog post, I believe the first step is to run jboss in debug mode. I have Jboss 5.1.0.GA. so I don't have the same files (standalone.sh) as mentioned in How to start JBOSS 7 in debug mode?">this Stack Overflow which covers it for Jboss 7.
How do I do this for Jboss-5.1.0.GA? In run.conf, I see these two lines:
# Sample JPDA settings for remote socket debugging
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
# Sample JPDA settings for shared memory debugging
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_shmem,address=jboss,server=y,suspend=n"
Is all I need to do uncomment one of those? Then in Intellij what would be the corresponding settings? Here:
We have to do 2 changes to debug remote java application that is running in JBoss
Configure in JBoss
Creating remote debugger in in eclipse
Open run.conf.bat(windows) or run.conf(Linux) file in JBoss bin folder.
go to the below lines
`# Sample JPDA settings for remote socket debugging`
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
and remove hash in JAVA_OPTS
# Sample JPDA settings for remote socket debugging
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
Restart the server if it is started.
2. In Eclipse, Run -> Debug configuration -> Remote Java Application and create a new.
Note that you have to give port that is mentioned in run.conf.bat file
I know this is an old post but just answering it speciffic to intelliJ IDE
Step 1
In the JBOSS start-up we add the below line
JPDA options. Uncomment and modify as appropriate to enable remote debugging.
set JAVA_OPTS=-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n %JAVA_OPTS%
Step 2
Run JBoss with the above script
Step 3
In intelliJ under run/debug configuration add jboss like the screen grab below
Step 4
Start the JBoss config in debug mode by clicking on the debug icon.

Eclipse Remote debugging with jboss

How can I configure remote debugging in Eclipse with JBOSS server 4.x version?
So far,
Step1: I have modified the run.confg file. By uncommenting the below line. Sample JPDA settings for remote socket debugging:
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
Step2 : Then I configured Eclipse in debug configurations. It's saying:
Failed to connect to remote VM. Connection refused.
What you are asking is not specific to either Java EE or JBoss 4.x - you can debug any Java process in case you specified the remote debugging runtime parameters when starting the JVM.
In your setting the -Xdebug parameter is missing, so your line would be:
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
Now it should be able to connect, in case you are using the correct host and your specified port 8787. In case it's still not working, it's most likely a firewall issue blocking the port.

Remote debugging in eclipse with jetty server

I configured the debug configurations for remote debugging my maven project. I set the host as localhost and the port as 7000. I even ran the following command as the launch was not working:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=7000,suspend=n
However it is still not launching the remote VM and I cannot proceed with my debugging.
It gives the same error as:
Failed to connect to remote VM.Connection refused.
How should I proceed with solving this problem ?
you can issue the follwoing command from command prompt. mvnDebug jetty:run-exploded antrun:run Then you wil come to know on which port your jetty is listening to after that go to run->debug configuration from there you can debug your server.
In debug configuration you can find the option Remote Java Application here create one new debug configuration for new Remote java Application and also here you can define your new server
again mvnDebug jetty:run-exploded now you should see your new port.

Categories

Resources