Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I debug a jar at runtime?

I'm into a quite strange position (from my java-newbie point of view):

  1. using Eclipse I wrote a "java program" (some .java files with classes into) which essentially (batch) reads a text *.csv file, "evaluates" its contents, and writes out results into an *_out.csv text file. To locate the input file it uses a "file chooser" (got sample from here: http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html)

  2. I debugged all the code and, using the debugger, it works.

  3. I ran the code (the main class, which calls all the other in sequence) and it works, while in Eclipse.

  4. I exported all the project's contents into a "runnable jar" file.

Notice that, file chooser apart, this is mainly a "batch" which reads and writes: nearly no User Interface at all. While into Eclipse I shown some internal results using something like "if(debug) System.out.print("something to print");" providing to set "debug" TRUE while debugging and FALSE while in production environment.

ALL of the above worked!

Now, starting the runnable jar (double-click on the jar file, in Win/XP), I can see the file chooser and I can use it but, after choosing the input file... nothing more: (having no user interface) I don't know if the file was read, I don't see any generated output file, and I've even no "console" to list any intermediate debug message, to see if the jar is working, even if I re-export it with the debug variable set to TRUE.

Is there a way to "runtime debug" the running jar (like VB's MsgBox, or something other)? some kind of "log file" I can "enable" or look into? (obviously, as my jar is not writing the result file, I just can't try writing a *.log too) I have also to say I just can't install other than Eclipse on my machine (and just been lucky it ran), so no usual developer's tools, utilities and other useful things.

like image 624
eewing Avatar asked Nov 07 '13 17:11

eewing


People also ask

How do I open a jar file in Java Runtime Environment?

Right-click on the JAR file. Go to “Open With Other Applications”. Select Show other applications. Select Open With OpenJDK Java X Runtime.

Can we debug jar in IntelliJ?

Run Debug Configuration: JAR Application This run/debug configuration enables you to run applications started via java -jar <name>. jar command.

Can we debug jar in eclipse?

First open the jar file using JD(Java Decompiler), then click on File -> Save JAR Sources and it will become a . zip file containing the java source files. Then you can add this source zip file in the debug configuration using add source. It will work then for sure.


1 Answers

http://www.eclipsezone.com/eclipse/forums/t53459.html

Basically run it with:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 

The application, at launch, will wait until you connect from another source.

so the CLI command will be:

java -jar yourJarFileName.jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 
like image 191
RamonBoza Avatar answered Oct 04 '22 01:10

RamonBoza