I want to be able to run external shell tools from within Eclipse, especially builders. How can I set up Eclipse so an external command gets run when a build is needed? Also, how can I configure Eclipse so that I can tell it to run an external command manually on demand?
What sparked this need was that I want to be able to perform an sbt build from within Eclipse. I am aware of ScalaIDE, but it doesn't work for my Android development.
Here's how I am doing it with sbt and the android-plugin presently. These instructions will apply equally well to any kind of external tool you'd like to run from within Eclipse.
It's possible to require the developer to start the build manually or to treat the build as an Eclipse builder. The builder can be configured to run by various triggers (a manual build, clean build, after file save, etc.)
To configure sbt to run as builder:
Import your sbt project into Eclipse. (See this answer.)
Right-click on the sbt project, click properties.
Click the builders item under type filter text
.
Uncheck or remove the Java builder. If you don't, it may interfere with the external builder. If your external tool isn't building, but doing something post-build, you can leave the Java builder.
Click the New button. Select Program, and click OK.
In the Edit Configuration window, enter a name for the builder in the name field.
For the location, browse to your java executable. If you're not sure where it is or which java executable you normally use, take a look at the script you normally use to run sbt.
Choose the root directory of your sbt project in the Working Directory field. If you already have your sbt project in Eclipse, you can browse workspace, otherwise browse the file system to find it.
In the arguments field, paste Java parameters, the path to your sbt-launch.jar
(again, see your usual command-line sbt launch script) plus whatever commands you want sbt to perform. For example, on Windows I use:
-Djline.terminal=jline.UnixTerminal -XX:MaxPermSize=256m -Xmx512M -XX:+CMSClassUnloadingEnabled -jar c:/cygwin/home/[username]/bin/sbt-launch.jar android:package-debug android:start-emulator
If you're building for Android, you'll need to create a new environment variable to indicate where the Android SDK is located. Click on the environment tab, click New, and then fill in the name field with ANDROID_SDK_ROOT
and the value with the path to your Android SDK.
Click on the build options tab and choose under what conditions you'd like to run the builder.
To instead configure sbt to run as an external program that will only be run when explicitly requested:
From Eclipse, look on the toolbar for a run button that has a picture of a suitcase on the lower-right corner. Click it and select "External Tools Configurations".
In the External Tools Configurations window, click the Program item under the "type filter text" box.
Click the "New Launch Configuration" icon on the top-left corner of the External Tools Configurations window.
Enter a name for the configuration in the name field.
For the location, browse to your java executable. If you're not sure where it is or which java executable you normally use, take a look at the script you normally use to run sbt.
Choose the root directory of your sbt project in the Working Directory field. If you already have your sbt project in Eclipse, you can browse workspace, otherwise browse the file system to find it.
In the arguments field, paste Java parameters, the path to your sbt-launch.jar
(again, see your usual command-line sbt launch script) plus whatever commands you want sbt to perform. For example, on Windows I use:
-Djline.terminal=jline.UnixTerminal -XX:MaxPermSize=256m -Xmx512M -XX:+CMSClassUnloadingEnabled -jar c:/cygwin/home/[username]/bin/sbt-launch.jar android:package-debug android:start-emulator
If you're building for Android, you'll need to create a new environment variable to indicate where the Android SDK is located. Click on the environment tab, click New, and then fill in the name field with ANDROID_SDK_ROOT
and the value with the path to your Android SDK.
Then to launch, just click apply then click run. In the future, you can just click the run button with the suitcase again and pick the configuration directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With