如何配置 Eclipse 以运行外部构建器或 shell 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8248567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I configure Eclipse to run an external builder or shell command?
提问by Jeff Axelrod
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?
我希望能够从 Eclipse 中运行外部 shell 工具,尤其是构建器。如何设置 Eclipse 以便在需要构建时运行外部命令?另外,如何配置 Eclipse 以便我可以告诉它按需手动运行外部命令?
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.
引发这种需求的是我希望能够从 Eclipse 中执行 sbt 构建。我知道 ScalaIDE,但它不适用于我的 Android 开发。
采纳答案by Jeff Axelrod
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.
这是我目前使用 sbt 和 android-plugin 的方式。这些说明同样适用于您希望在 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.)
可能需要开发人员手动启动构建或将构建视为 Eclipse 构建器。构建器可以配置为通过各种触发器运行(手动构建、干净构建、文件保存后等)
To configure sbt to run as builder:
将 sbt 配置为作为构建器运行:
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.
将您的 sbt 项目导入 Eclipse。(请参阅此答案。)
右键单击 sbt 项目,单击属性。
单击 下的构建器项
type filter text
。取消选中或删除 Java 构建器。如果不这样做,它可能会干扰外部构建器。如果您的外部工具不是在构建,而是在进行构建后的操作,您可以离开 Java 构建器。
单击新建按钮。选择程序,然后单击确定。
在“编辑配置”窗口中,在名称字段中输入构建器的名称。
对于位置,浏览到您的 java 可执行文件。如果您不确定它在哪里或您通常使用哪个 java 可执行文件,请查看您通常用于运行 sbt 的脚本。
在“工作目录”字段中选择 sbt 项目的根目录。如果您的 sbt 项目已经在 Eclipse 中,您可以浏览工作区,否则浏览文件系统找到它。
在参数字段中,粘贴 Java 参数、您的路径
sbt-launch.jar
(再次参见您常用的命令行 sbt 启动脚本)以及您希望 sbt 执行的任何命令。例如,在 Windows 上我使用:-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
如果您为 Android 构建,则需要创建一个新的环境变量来指示 Android SDK 所在的位置。单击环境选项卡,单击新建,然后
ANDROID_SDK_ROOT
用 Android SDK 的路径填写名称字段和值。单击构建选项选项卡并选择您希望在什么条件下运行构建器。
To instead configure sbt to run as an external program that will only be run when explicitly requested:
将 sbt 配置为仅在明确请求时运行的外部程序:
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.
在 Eclipse 中,在工具栏上查找右下角有一个手提箱图片的运行按钮。单击它并选择“外部工具配置”。
在“外部工具配置”窗口中,单击“类型过滤器文本”框下的程序项。
单击“外部工具配置”窗口左上角的“新启动配置”图标。
在名称字段中输入配置的名称。
对于位置,浏览到您的 java 可执行文件。如果您不确定它在哪里或您通常使用哪个 java 可执行文件,请查看您通常用于运行 sbt 的脚本。
在“工作目录”字段中选择 sbt 项目的根目录。如果您的 sbt 项目已经在 Eclipse 中,您可以浏览工作区,否则浏览文件系统找到它。
在参数字段中,粘贴 Java 参数、您的路径
sbt-launch.jar
(再次参见您常用的命令行 sbt 启动脚本)以及您希望 sbt 执行的任何命令。例如,在 Windows 上我使用:-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
如果您为 Android 构建,则需要创建一个新的环境变量来指示 Android SDK 所在的位置。单击环境选项卡,单击新建,然后
ANDROID_SDK_ROOT
用 Android SDK 的路径填写名称字段和值。然后启动,只需单击应用然后单击运行。以后你可以带着行李箱再次点击运行按钮,直接选择配置。