Launching a Java Debugger in Eclipse – A Myriad of Options

How to start a debugger? Seriously? Is it really worth a story? Let us find out about the different features of launching..

We need to of course launch in Debug mode :

Debug Button

And then pick up the following option:

Pull down from the debug button

For the detail-oriented, there is this Show Command line option:

click to see command line

ok, let’s escape back to the world of ui fast:

There are different launch options as you can see — as:

Launch Options

Java Application, Eclipse Application, JUnit, etc. Let’s go through some of them. Please remember the following button to start a new launch configuration:

Button to Start a new launch

Java Application

Clicking on a new Java launch configuration gives us the following:

Create a New Java Application Launch Configuration

Main

Let’s look at the “Stop in main”

This is equivalent of putting a breakpoint in the main method albeit implicitly.

Moving on to the Arguments tab, we can put variables out there both for program and vm as shown below.

Additionally, if you want to add some pre-defined variables, click on variables for the list

The JRE Tab:

Click on the Installed JREs to installed your favourite JRE here.. How is this helpful? Especially if you are using one of the later JREs for testing out preview features

Environment Variables:

Click Add to create new env, Click select to add existing ones.

You have other options as well — appending — works well for paths /replacing — good for single element vars

Prototypes:

Click on link to a prototype — let us say for now its just a template. will come back to this.

Eclipse Application

You can start a new launch as Eclipse Application. In that case, you have an additional option called Tracing as shown below:

Click on one of the plugins and a list of options gets thrown up — these are debug messages that would help which are existing in the plug-ins. Where is this useful? Well one practical case or cases we found this one quite popular is for people using DOM — sometimes to validate that these plugin indeed give the correct data to the upper layer — for example, the source length of a construct as shown below in the child eclipse.

Junit

The keep alive option:

This is useful when the start-up times are more — no example here

And one point to note here is that the tab is not “main” but “Test”

Junit Plug-in Test

Here as expected you will have a “Main” tab, a “Test” tab and a “Tracing” tab.

Prototypes:

More like a template -> Create one prototype using

And now, click on “Prototype” tab for the list of options:

What’s the use? One place I found useful is again while testing out preview features — say create one prototype — lets call it EA, standing for early access and add a few more VM arguments as shown below:

New options appended: — enable-preview — release 21

But how do we use this?

Create a new configuration and just link to the prototype you want. An easier method is just to click P

Debug Favourites

Click to add configuration that’s faster to acces

Use up and down as well. And these will be added as favourites as shown below:

Launch Groups

This is an interesting thing — sometimes you want run a few launches together — A typical use which I find is when I test my Java compiler — I want to run the junit test case, as well as to figure out how it behaves when a child eclipse is spawned. Though fundamentally, the bottom-most layer is the same, the upper layers are different in these cases and hence if the fix is in bottom most layer, it helps to launch these two together. For that we have something called launch groups

And these do have interesting options as well — eg: Launch mode — remember, launch is not just “Debug”, you can “run” as well.

More interesting option is the “post launch option” — these have some intriguing options again:

The above “Wait until terminated” will cause the Junits to run one after the other..More interesting option of the below:

The second test will happen after “First” gets prints on to the console — In the XDelayTest, the first test prints that message — so essentially, the first test of XDelayTest finishes and then these two run in parallel:

Here, “First” gets printed and then the XTest of LGTwo starts.

And trivia: click on ctrl-<n> to invoke the launch no — n

External Launch Configuration:

You can add your own launcher and create a new external launch configuration as shown below:

Exporting and Importing a Launch Configuration

You just want to export a config to a file:

You can import using the Eclipse preferences..

Go, Launch your Eclipse!!

Total
0
Shares
Previous Post

Journey to junior

Next Post

Code Wizardry: Casting Spells to Fix Bugs

Related Posts