Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure Eclipse to run an external builder or shell command?

Tags:

eclipse

build

sbt

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.

like image 850
Jeff Axelrod Avatar asked Nov 23 '11 20:11

Jeff Axelrod


1 Answers

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:

  1. Import your sbt project into Eclipse. (See this answer.)

  2. Right-click on the sbt project, click properties.

  3. Click the builders item under type filter text.

  4. 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.

  5. Click the New button. Select Program, and click OK.

  6. In the Edit Configuration window, enter a name for the builder in the name field.

  7. 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.

  8. 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.

  9. 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

  10. 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.

  11. 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:

  1. 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".

  2. In the External Tools Configurations window, click the Program item under the "type filter text" box.

  3. Click the "New Launch Configuration" icon on the top-left corner of the External Tools Configurations window.

  4. Enter a name for the configuration in the name field.

  5. 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.

  6. 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.

  7. 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

  8. 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.

  9. 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.

like image 185
Jeff Axelrod Avatar answered Sep 22 '22 14:09

Jeff Axelrod