July 11, 2005
Eclipse tip: context-dependent launches
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) {
System.out.println(args[0]);
}
}
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!
Posted by cedric at July 11, 2005 04:12 PM
Hi Cedric,
Earlier today, "discovered" that my code templates include the enclosing_method variable. We're adding logging to our code and having a template that can use variables is cool.
But I wish that Eclipse has the macro capability of Visual Studio/Emacs that would make life more easier.
BR,
~A
At some point I've used "current project location" variable to share external tools config for Ant xdoclet target between several projects.
Anjan, it is not quite macros, but also could be quite powerful. http://eclipseexeditor.sourceforge.net/
Hey, Cedric, do you fancy to add support of the groovy/baeanshell/javascript into this plugin? :-)
It would make you happy: It would make you happy: http://www.eclipse-plugins.info/eclipse/plugin_details.jsp?id=1069
Cedric, I took your challenge and played around with some of the other variables. Here are some I really liked...
The ${file_prompt} variable is really neat, because you can then write a simple command line program that expects a fully qualified filename of some input file to process as the first argument. Use ${file_prompt} when you run it, and bingo, up pops a nice GUI dialog to let you select the file. When you click OK on the dialog, off your program goes with the fully qualified filename as args[0].
The ${folder_prompt} variable works the same way, but brings up a folder selection dialog.
${string_prompt} is even more generic, in that it brings up a plain vanilla dialog and lets you enter any text you want into it. If you enter "a b c" into the dialog then hit the OK, you will get args[0]=a, args[1]=b, etc. If you want args[0] to return the entire string, just enclose ${string_prompt} in quotes.