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

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)

Related

Readline support when running programs in Eclipse

I've just started using JLine for console input in my programs. In a bash shell, this works great. In the Eclipse Console view, nothing useful works - no history, no command completion.
Is there a way to get this working? (I'm on OSX in case that's relevant).
Note: I've looked at the Local Terminal plugin (https://code.google.com/p/elt/) and the TM Terminal (https://marketplace.eclipse.org/content/tm-terminal) but these both seem to be about running a general terminal, rather being used as a terminal for the programs I'm running. However, I may be missing something.

How do I attach to a process in Eclipse?

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.

debug application by running .sh file using eclipse

I have a .sh file which runs independently on Linux server to sync some data but now there is some problem with the sync so I wanted to run this .sh file in debug mode in eclipse so that I can check my java code where the problem is?
Is there any plugin or options available in eclipse to do this.
Please let me know if you need any further information.
If you want to debug your java code which your shell script invokes, just write a wrapper java code which invokes your main java code, and you can easily debug using eclipse.
What is the content of this .sh file? Is it running a JAR?
If so, you can remotely debug a java code. The following blog explains using screenshots: http://javarevisited.blogspot.co.uk/2011/02/how-to-setup-remote-debugging-in.html
I don’t think we can use shell script debugger in the Java debugger session. i.e you need to debug java code and shell script code separately in separate debug sessions.
You can use basheclipse to debug shell script, this will only work with shell script editor ShellEd.
Also check the open tickets for debugging in ShellEd.
Note
Outside eclipse you can try http://bashdb.sourceforge.net/

How to debug Java and Perl code in Eclipse in same debug session?

Setup:
I am working on a Java project which invokes some Perl scripts.
Problem:
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails. It is an extremely strange and annoying bug.
I am able to debug Perl in Eclipse using EPIC plugin. And of course, I can debug Java code. It would be helpful to debug Java and Perl code in the same debug session in Eclipse, so that I can see whats different happening when the script is invoked via Java code.
Not sure if this is even possible, but if anyone has any idea, please share.
Thanks.
Perl has some remote debugging capabilities, so you can get what you need, I think. I don't use EPIC, so I don't know if you'll be able to do it all within Eclipse.
Set the environment variable named PERLDB_OPTS to have the value RemotePort=<host>:<port>. Then, start Perl with the -d flag. Instead of the debugger trying to interact with standard IO on the invoking terminal, it will attempt to connection to host:port.
Here's a Unix-y example. I've got a Perl script hello.pm and two terminal windows open.
First terminal
$ nc -l 12345
That's started NetCat as a dumb server listening on port 12345. If you don't have a server listening before Perl starts, it won't work.
Second terminal
$ export PERLDB_OPTS=RemotePort=localhost:12345 # set the env variable
$ perl -d hello.pm
Now the script is running. Back on the first terminal, I see
First terminal
main::(hello.pm:1): print "hello\n";
DB<1>
I'm in the Perl debugger and ready to go!
I know that at least the Komodo IDE has support for remote debugging, and there's a Perl Monks post on doing it with Emacs, so you can get something more than the command line even if it's not Eclipse. Good bug hunting!
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails.
I suggest that you check that you are running the same version of Perl in the two "contexts"; i.e. when the Perl app is run from the command line and from Java.
If that's not the problem, check the environment variables.
The other approach to solving this problem would be to focus on why the program is going wrong, not on how / why the contexts are different. Look at the evidence that you have, and look at ways to gather more evidence ...
The potential problem with trying to do this using a Perl a debugger (in an IDE or stand-alone) is that you are actually running Perl in third "context" which might be different from either or both of the existing ones.
Using a debugger may work ... or it may leave you even more confused.

How can I remote debug my rcp application?

Because my RCP eclipse application fails when run outside of eclipse, but works correctly when running inside of eclipse, I am attempting to use eclipse to remotely debug my application as it's running outside of the eclipse environment.
I am using 32 bit Eclipse 3.6.1 on a 64 bit Windows 7 machine. I am using 32 bit Java 1.6 update 37. I use the Eclipse Product export wizard to package the app, and I end up with an eclipse.exe. I have created a Remote Debug Configuration and set it to use port 8765 (random number). For debugging purposes, I start the app from the command line using this line:
eclipse.exe -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8765
Depending on whether I am attaching or listening via my Eclipse debugger, I will add the server=[y/n] option to this command line but it seems not to make any difference.
For the configuration Connection Type I have tried both Standard (Socket Listen) and Standard (Socket Attach). When I try Socket Listen, my debugger will start listening - "Waiting for vm to connect at port 8765", but when I start my app through the command line, the app starts fine but the debugger never attaches.
When I try Socket Attach, I start the app first using the command line, then when I attempt to attach using eclipse, I get the message "Failed to connect to remote VM. Connection refused"
I've tried all the various combinations of address: localhost, 127.0.0.1, and my local IP address. I get the same result each time.
Thanks for any help!
You are missing the -vmargs parameter. Try "eclipse.exe -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8765"
I was searching for the same thing and found the answer in this helpful post http://blog.ankursharma.org/2010/05/remote-debugging-eclipse.html
this is better:
http://exploreeclipse.blogspot.com/2016/05/eclipse-rcp-remote-debugging.html
Defining the server and suspend arguments
$./TOS_BD-macosx-cocoa -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8989
Another way of debugging your RCP application is to launch it with "-console" "-consolelog". This gives you the osgi console, where you can examine which bundles did (not) start, the services that are exported etc. Type help to get a list of commands available.

Categories