如何在 Sublime Text 3 中构建 Scala 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24230000/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:21:11  来源:igfitidea点击:

How to build Scala applications in Sublime Text 3?

scalasbtsublimetext3

提问by アレックス

I'd like to be able to build Scala applications in Sublime Text 3 on Mac 10.9.3. I have Scala 2.11.1 and sbt 0.13.5 installed and they all work fine. I installed them by homebrew.

我希望能够在 Mac 10.9.3 上的 Sublime Text 3 中构建 Scala 应用程序。我安装了 Scala 2.11.1 和 sbt 0.13.5,它们都可以正常工作。我通过自制软件安装了它们。

However, I can't seem to find how to create a build system for Scala projects. For example, this one doesn't work:

但是,我似乎找不到如何为 Scala 项目创建构建系统。例如,这个不起作用:

{
    "cmd": ["sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

I found a couple of different ones as well but they didn't work for me, either. Your thoughts?

我也找到了几个不同的,但它们也不适合我。你的意见?

UPDATE:

更新

[Errno 2] No such file or directory: 'sbt'
[cmd: ['sbt', 'test']]
[dir: /Users/alex/Documents/projects/scala/dir1]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
[Finished]

UPDATE2:

更新2:

{
    "cmd": ["/usr/local/bin/sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

An app:

一个应用程序:

class MainTest extends App {
  println("Hellowa!")     
}

The output:

输出:

 [0m[[0minfo[0m] [0mSet current project to scala (in build file:/Users/alex/Documents/projects/scala/)[0m
[0m[[0minfo[0m] [0mCompiling 1 Scala source to /Users/alex/Documents/projects/scala/target/scala-2.10/classes...[0m
[0m[[32msuccess[0m] [0mTotal time: 4 s, completed Jun 16, 2014 4:51:38 PM[0m
[Finished in 7.2s]

采纳答案by Seth Tisue

Homebrew installs executables in /usr/local/bin, but the error text you have now provided shows that that directory isn't in your path.

Homebrew 在 中安装可执行文件/usr/local/bin,但您现在提供的错误文本显示该目录不在您的路径中。

Two ways you could fix it:

您可以通过两种方法修复它:

1) Change "cmd": ["sbt", "test"],to "cmd": ["/usr/local/bin/sbt", "test"],

1)"cmd": ["sbt", "test"],改为"cmd": ["/usr/local/bin/sbt", "test"],

2) Add /usr/local/binto your PATHenvironment variable. Note that you'll need to do this in such a way that GUI apps like Sublime Text notice the change; see e.g. Setting environment variables in OS X?for details

2)添加/usr/local/bin到您的PATH环境变量。请注意,您需要以这样的方式执行此操作,以便 Sublime Text 等 GUI 应用程序注意到更改;参见例如在 OS X 中设置环境变量?详情

回答by Jacek Laskowski

Could SublimeSBTthat's "Scala SBT build tool integration for Sublime Text 2 and Sublime Text 3."be a solution?

莫非SublimeSBT这是“为崇高文字2和崇高的文本3斯卡拉SBT构建工具集成” 是一个解决方案?

回答by Bolek Tekielski

Why wouldn't you :D I am using SublimeSBT for quite some time, and the only complexity it's invoking cmd+shift+pfollowed by sbt start continuous testing. I would advice you to give SBTSublime a try before baking your own build system.

你为什么不:DI 使用 SublimeSBT 已经有一段时间了,它调用的唯一复杂性cmd+shift+psbt start continuous testing. 我建议你在烘焙自己的构建系统之前先尝试一下 SBTSublime。

回答by gwenzek

Personally I use SublimeREPL that support SBT. SublimeREPL allows you to launch SBT from Sublime. This avoided me to download another package, cause I already used SublimeSBT for python. I wanted a minimal configuration to code in scala, because my IDE was to slow. I first try to use my on build system but end up using SBT. The SBT offers great advantages in comparaison to other way of building your project.

我个人使用支持 SBT 的 SublimeREPL。SublimeREPL 允许您从 Sublime 启动 SBT。这避免了我下载另一个包,因为我已经将 SublimeSBT 用于 python。我想要一个最小的配置来在 Scala 中编码,因为我的 IDE 很慢。我首先尝试使用我的构建系统,但最终使用了 SBT。与其他构建项目的方式相比,SBT 具有很大的优势。

First it compiles only files that need to (those who have been modified, and those who depend on them). Second it's very handy for importing library. One line into your build.sbt file allows you to import library from github (usually this line is explicited on the github main page). And third you can compile on every save, with the command "~compile", or "~; compile; runMain 'mainclass' "

首先它只编译需要的文件(那些被修改的文件,以及那些依赖它们的文件)。其次,它对于导入库非常方便。build.sbt 文件中的一行允许您从 github 导入库(通常这一行在 github 主页上明确显示)。第三,您可以在每次保存时编译,使用命令“~compile”或“~; compile; runMain 'mainclass'”

I find the later pretty useful as it is often long to compile with scala. I often start to add a simple function, save, and while it's compiling I improve my first draw.

我发现后者非常有用,因为用 Scala 编译通常很长。我经常开始添加一个简单的函数,保存,并在编译时改进我的第一次绘制。

The main constraint is you have to put your code in src/main/scala or src/main/java if you have some Java files too, and you have to open the whole root directory with sublime.

主要的限制是你必须把你的代码放在 src/main/scala 或 src/main/java 中,如果你也有一些 Java 文件,你必须用 sublime 打开整个根目录。

回答by Yuri

Windows only! If you already add the bin folder to the PATH variable:

仅限窗户!如果您已经将 bin 文件夹添加到 PATH 变量:

{
    "cmd": ["sbt.bat", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}