Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print Line numbers as and when java code is executed

H All, I want to trace which lines are executed in my code so that I can highlight those lines. Due to this i am able to trace the code which is not tested.

i found out that JDB is way through which I can actually debug my application but I am not able to connect JDB with my eclipse code which is running. So in good scenario what I want is my code is running on eclipse and I am connected to that code via JDB and able to get all the line numbers which are executred

like image 376
nikhil deshpande Avatar asked Jun 22 '26 18:06

nikhil deshpande


2 Answers

This will get you the line number in the file that the stack trace code is called in:

Thread.currentThread().getStackTrace()[1].getLineNumber();

This will get you the line number in the file where the method that contains the stack trace code is called:

Thread.currentThread().getStackTrace()[2].getLineNumber();
like image 93
Sintrias Avatar answered Jun 24 '26 07:06

Sintrias


I think Eclipse Debugger would do the job, so you can go trough you code line by line

http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/junor

but this is included in nearly any ide

like image 29
ABLX Avatar answered Jun 24 '26 09:06

ABLX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!