This feature has probably been in Eclipse for a while but I only recently
discovered it, and I’ve found it quite useful already:  Eclipse lets you
define launch configurations that depend on the current selection.

Consider the simple following program that prints out the parameter passed on
the command line:

public class Echo {
  public static void main(String[] args) {

Then create a launch configuration and press the Variables button:

Choose the variable "selected-text":

And close the launch dialog.  Next select some text in a buffer, say the
first line of the class:

Launch, and you get:

public class Echo {

I have used this feature quite a few times already to launch groups of tests
with TestNG by simply selecting them from my Java source or the XML file, but I’m sure there are many other uses.

There are plenty of other interesting variables to choose from, by the way,
try them out and report here!