Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a java application is in debug mode in Eclipse

I want to change the logging level depending if I'm debbugging or not, but I can't find a code snippet to check if the application is running in debug mode.

I'm using eclipse to debug the application, so if the solution only works within Eclipse it will be fine.

like image 994
Serxipc Avatar asked Jul 10 '09 11:07

Serxipc


People also ask

How do you check debugging in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

How do I get out of debug mode in Eclipse?

Right Click the project and Open Properties. Then Select Run/Debug Setting from there you will find all the launch Configured. Delete all the launch and Run the application.

What is debug mode in Eclipse?

Eclipse allows running an application in Debug mode which helps with stepping through each line of code in a program. Eclipse also provides a Debug Perspective which is a set of views grouped together that help inspect code and make the debugging process very effective.


1 Answers

Found the answer on how-to-find-out-if-debug-mode-is-enabled

boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().     getInputArguments().toString().indexOf("-agentlib:jdwp") > 0; 

This will check if the Java Debug Wire Protocol agent is used.

like image 77
topgun_ivard Avatar answered Sep 21 '22 09:09

topgun_ivard