How to run an Eclipse Run Configuration from the command line

· Java
Author

It’s easy to run an Eclipse Run Configuration from a shell outside of Eclipse if you know how. This article will show the trick. First of all it’s assumed that you have Eclipse set up, are working on a (Java) project and already have some part that can be executed with the Eclipse Run As context menu. It can be a web application or a Java (command line) application. It’s not trivial to replicate this Eclipse setup outside of it by hand, because class paths for Eclipse projects are often quite long and complicated. It’s also assumed that you already have Ant set up outside of Eclipse. See this article for more details on how to get Ant set up that way.

Steps

Now backup any existing build.xml files in your project.

Then select File-Export…-General-Ant Buildfiles and Eclipse will generate a build.xml file that covers building of your application a well as running any of the existing Run Configurations.

Review the generated build.xml file, and note that names of any generated run targets (they are the ones that only consist of a java task, and are not related to cleaning, building or compiling).

Then in a command shell simply type:

cd your-workspace/your-project
/your/ant/install/path/bin/ant YourRunConfigName

Conclusion

As you can this is one of the many features of Eclipse that are very well thought-out but not easy to find. Once you know the right menu option the rest is pretty straightforward. Do note however that if you add Run Configurations to your project or change Run settings your new build.xml will not be automatically updated. You will have to run File-Export…-General-Ant Buildfiles again.

Leave a Comment