0

I have coded in c++ in visual studio for several years.

I am now working in java with eclipse.

the java programs are launched from a .bat file so I cannot breakpoint them to debug.

Without being able to step through my code i am finding it very hard to find the root cause of the error as the thrown exception is not usually the source of the problem.

How can I debug my code without access to breakpoints ?

Skeith
  • 2,512
  • 5
  • 35
  • 57
  • Look at the contents of the bat file - chances are it's calling a main method somewhere. You just need to find this and you'll be able to run it from within eclipse / debug it as normal. – Ben J Jun 06 '11 at 09:42
  • @Ben J the bat file passes in 2 values to the main function, how can i do this from eclipse? – Skeith Jun 06 '11 at 09:43
  • 1
    If you use Eclipse, why do you run the Java programs from a .bat file? – musiKk Jun 06 '11 at 09:44
  • See http://stackoverflow.com/questions/373328/invoking-java-main-method-with-parameters-from-eclipse – Ben J Jun 06 '11 at 09:44
  • @musiKk not my choice, new job and this is how they do things, not saying its a good idea but I need to adapt – Skeith Jun 06 '11 at 09:46
  • If the app is launched from a .bat file, you can still attach the debugger to it. You just need to make sure you attach the debugger after the app starts and before the line you want to break at is executed. – Dave Jun 06 '11 at 09:49
  • A batch file is fine as a way of enabling end users to run the application, but if you want to attach a debugger to it and get useful output I think you will need to ensure the code is compiled with debug information (`javac -g`). Debugging from Eclipse is probably easier because it handles this automatically. – Ben Jun 06 '11 at 10:04

2 Answers2

3

You can find the main method, as suggested by Ben J, and run this from Eclipse. To pass arguments to it, edit the run configuration. e.g. Right-click on the main class, click "Run As" and then "Run Configurations...". Select the "Arguments" tab and enter whatever you need.

Or since you need to debug this, click "Debug As" and "Debug Configurations..." instead.

Ben
  • 2,348
  • 2
  • 19
  • 28
0

Use Maven or Ant to launch your programs, instead of a batch file. There is much better integration with Eclipse.

artbristol
  • 32,010
  • 5
  • 70
  • 103
  • could you explain your answer a bit more and I have to use a bat file – Skeith Jun 06 '11 at 09:47
  • OK if you have to use a batch file, fair enough. In Java, if you have tests, it's traditional to use JUnit or some other unit test framework to test your code, which integrates with Maven. See Ben J's link in the comments to your question for how to pass parameters to a main method. If that's all you're using your batch file for, you can probably get rid of it. – artbristol Jun 06 '11 at 09:51
  • There is a difference between testing and debugging. Especially when dealing with an existing application that has no unit tests, the debugger can be a real help. – Ben Jun 06 '11 at 09:58
  • Well, the title does say "test" to be fair, but the question asks about debugging. – Ben Jun 06 '11 at 10:06