The Eclipse dot launch file

Any Java class class could have its own static public (and void) main method, and any of such class could run as a standalone application in Eclipse. It is quite easy, right click on the class in the Package Explore, choose the "Run As" menu item, and finally select "Java Application".

Eclipse creates under the hood a default ".launch", a Java application configuration file, that will be used for each next request to run that class. We could modify it, or even create a number of different custom launch file to run our Java application with specific setups from within Eclipse.

By default the launch files are stored in a hidden folder in the metadata branch under the workspace directory, something like:
workspace\.metadata\.plugins\org.eclipse.debug.core\.launches\
There you could see all the .launch files available to Eclipse in that workspace. Instead of digging in the file system, you can see them opening the Run (and Debug) Configuration window that shows a filtered view of all the .launch files, from here you can easily create, edit and run your configuration files.

You could also create a specific folder in your project, and there modify a copy of the original .launch file as you please.

The .launch file is an XML that could be edited directly, if you are confident with its structure, or by Eclipse. You could set basically everything you would usually set in a script that runs the Java application directly from the operating system (program and JVM arguments, for instance), and in case of debug execution you could also set a breakpoint in the main class (there is a "Stop in main" check box in the main tab for launch configuration).

I found handy having a few local .launch files to test how my Java application react on being called with different configuration setup.

No comments:

Post a Comment