How do I attach to a process in Eclipse? - java

I am working with a large Java program that uses a command line shell to run integration tests. How do I attach eclipse to that process? Do I have to run the process and then attach it? It would be great to attach it to the shell process before I run it.

When you start your integration tests, add the following arguments to Java.
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
The suspend=y will pause startup until you attach with the debugger. In Eclipse, go to Run => Debug Configurations. Create a new "Remote Java Application" configuration and specify localhost as the host and 8000 as the port.

Related

How do I debug a maven project through UNIX mac terminal?

Seems like jdb doesn't work with maven. Everything I look up online is talking about debugging maven through Eclipse or IntelliJ. I'm literally just making this project through UNIX with maven. Normally I could debug using println or something but this is my first multi-threaded project and I have no idea where to start. Just want to step through the program line by line.
It sounds like you want to use mvnDebug to execute instead of just mvn, this will run in remote debugging mode. Then connect to the port from another terminal window while the program is running with jdb jdb -attach 8000 (this is the default port, it should print in the console what it's actually using)

Listen to serial port at STARTUP using java with arguments on Debian(Rasbian)

I've been stuck two weeks trying to figure out how to run this at startup.
I use the following chain of commands on the terminal:
1. source ~/.bashrc
2. source ~/.tinyos.sh
3. java net.tinyos.tools.Listen -comm serial#/dev/ttyUSB0:telosb | python demo.py`
The third command uses java to listen to the serial port and pipes it to a python script which cleans, converts and uploads to mysql localhost.
This works fine on ssh terminal. But ive tried using nohup+update-rc.d, upstart, systemd, crontab to make it run on startup and it just wont work! When I reboot and check logs / database, its as if the command never happened. I need this to run like a daemon and continue running until shutdown.
Thanks a lot.
How are you trying to execute the program ? Are there are permission issues accessing / executing the script ?
Which version of debian are you running - look at upstart scripts if you are running Jesse+
I'd put those three lines in a bash script and use upstart scripts to trigger them on start. Another option is to use supervisord to make sure that your scripts run and restart if for any reason the program crashes.

How to run Dropwizard app in debug mode with Eclipse?

I'm looking to run my Dropwizard 0.8.5 app in debug mode whereby:
The app is running locally, using JPDA; and
In my IDE (Eclipse) I set breakpoints and use a JPDA client to connect to my locally running app (I think this is how it goes)
For the server debug mode:
Typically my DW app runs from the command-line like so:
java -jar build/libs/myapp.jar server src/test/resources/myapp-local.yml
So what are the command-line args to get this running in debug mode (JPDA), or what are the modifications to myapp-local.yml needed to accomplish this?
For Eclipse/JPDA Client
I assume I just set breakpoints and then create a new Debug Configuration inside Eclipse, but not sure what arguments/configs to set this Configuration up with. Any ideas?
Just run the main class (the one that extends Application<T>) in debug mode. You will need to set the program parameters as "server src/test/resources/myapp-local.yml" in your run configurations.

Running Swing-Tests remotely on a Windows7-Jenkins-Slave

I already managed to set up a Jenkins-Slave on a Windows 7(x64) machine. I'm also able to attach Jobs to the slave and they get succesfully executed. But all tasks seem to be running in headless mode!? We have some graphical Swing-Tests that are starting a Swing GUI and executing Macros on it. When executing the corresponding Maven-Command manualy on the slave-node
mvn -B -f C:\Jenkins\workspace\3-Test-Script-GUI-Test\pom.xml clean test
everything works fine, but when triggering this command via Jenkins the Swing-GUI doesn't open and the tests fail.
Are jenkins-jobs by default triggered in headless mode or is there any other configuration that could help me to resolve this problem?
The jenkins-slave.xml looks as follows:
<executable>javaw.exe</executable>
<arguments>-Xrs -jar "%BASE%\slave.jar" -tcp %BASE%\port.txt</arguments>
The manual tests may (appear to) work when run from an X11 session running on the host, as the X server functions as valid peer for AWT components. Some alternatives (VNC, Xvfb) for headless mode are mentioned here.

What is the default properties that eclipse uses to launch a java process in its debugging mode?

I would like to connect to java process started by eclipse using a command line debugger but not sure what default properties of the eclipse launched java process are ? I wouldn't mind using attaching using sockets but not sure how much slower that would be ?
how about
-Xdebug -Xnoagent -agentlib:jdwp=transport=dt_socket,suspend=n,address=localhost:12345
then you can attach a java debugger to port 12345
I investigated on the differences of Java application startup in Eclipse between "Run" and "Debug". I used Sysinternals' Process Explorer to see the command line of the java process that Eclipse forks when starting a Java application with either option. (I'm on a Windows 7 system)
With "Run HelloWorld"
"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld
.......
With "Debug HelloWorld"
"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:2404 -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld
(The address port changed in succeeding invocations, e.g. it became address=localhost:2564 at the next invocation.)
So java (or javaw) actually gets started with different options depending on whether "Run" or "Debug" was used: the "Debug" start-up adds an additional agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:NNNN option. This is a standard way of putting a JVM into debuggable mode. The HelloWorld program will first wait for its debugger to successfully connect to it before continuing (option suspend=y). The HelloWorld JVM will connect itself automatically to some debugger running on address localhost:NNNN (... option address=localhost:NNNN and implicit default option server=n). (... Oracle provides authoritative information on the agentlib start-up options)
Eclipse itself will act as the debugger application providing a port NNNN. The HelloWorld JVM will connect to this port, via its own port of number NNNN+1 (one can see a process's used ports with Process Explorer on that process's TCP/IP tab).

Categories