如何使用 sbt-eclipse 创建项目的 Eclipse 项目文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24687698/
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 to use sbt-eclipse to create Eclipse project files of a project?
提问by Classified
I followed the official documentationto set up the plugin in my sbt project:
我按照官方文档在我的 sbt 项目中设置插件:
- Added
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
to~/.sbt/plugins/plugins.sbt
file cd
ed to a project and ransbt
- In sbt shell, typed
eclipse
- 添加
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
到~/.sbt/plugins/plugins.sbt
文件 cd
编辑到一个项目并运行sbt
- 在 sbt shell 中,输入
eclipse
That's where I faced the following error:
那就是我遇到以下错误的地方:
> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse (similar: sbteclipse)
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error] ^
What am I missing?
我错过了什么?
Thanks in advance for any help you can give me.
在此先感谢您能给我的任何帮助。
$ /opt/sbt-0.13.5/bin/sbt
[warn] The global sbt directory is now versioned and is located at /Users/first.last/.sbt/0.13.
[warn] You are seeing this warning because there is global configuration in /Users/first.last/.sbt but not in /Users/first.last/.sbt/0.13.
[warn] The global sbt directory may be changed via the sbt.global.base system property.
[info] Loading project definition from /Users/first.last/git/myproject/project
[info] Set current project to myproject (in build file:/Users/first.last/git/myproject/)
> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error] ^
回答by Jacek Laskowski
I'm using sbt 0.13.5.
我正在使用 sbt 0.13.5。
$ sbt --version
sbt launcher version 0.13.5
In an emptydirectory executed sbt about
to check the build/sbt setup.
在一个空目录中执行sbt about
以检查 build/sbt 设置。
$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
[info] This is sbt 0.13.5
[info] The current project is {file:/Users/jacek/sandbox/sbteclipse/}sbteclipse 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, net.virtualvoid.sbt.graph.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
No files are in the directory (disregard target
since it's automatically created by sbt upon startup and can be removed at any time).
目录中没有文件(忽略,target
因为它是由 sbt 在启动时自动创建的,可以随时删除)。
$ tree
.
`-- target
1 directory, 0 files
I then ran the sbt shell with sbt
to ensure no eclipse
command existed.
然后我运行 sbt shellsbt
以确保不eclipse
存在任何命令。
$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
> eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse (similar: sbteclipse)
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error] ^
I could reproduce your issue. Moving on to setting up the plugin - I did notclose the sbt shell.
我可以重现你的问题。移动到设置插件-我也没有接近的SBT外壳。
Following the documentation closelyI opened ~/.sbt/0.13/plugins/plugins.sbt
to have it as follows:
密切关注文档,我打开~/.sbt/0.13/plugins/plugins.sbt
它如下:
$ cat ~/.sbt/0.13/plugins/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
With the plugin in the file, I fired reload
in the sbt shell to load the changes.
使用文件中的插件,我reload
在 sbt shell 中触发以加载更改。
> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbteclipse (in build file:/Users/jacek/sandbox/sbteclipse/)
> eclipse
[info] About to create Eclipse project files for your project(s).
[info] Updating {file:/Users/jacek/sandbox/sbteclipse/}sbteclipse...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] sbteclipse
As you can see the plugin was properly loaded and generated the files. Follow the steps and you should have the plugin installed with no issues.
如您所见,插件已正确加载并生成文件。按照步骤操作,您应该没有问题地安装了插件。
回答by zinking
For sbt 0.13 and up
对于 sbt 0.13 及以上
Add sbteclipse to your plugin definition file. You can use either:
将 sbteclipse 添加到您的插件定义文件中。您可以使用:
the global file (for version 0.13 and up) at ~/.sbt/0.13/plugins/plugins.sbt
the project-specific file at PROJECT_DIR/project/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
位于~/.sbt/0.13/plugins/plugins.sbt的全局文件(适用于 0.13 及更高版本)
PROJECT_DIR/project/plugins.sbt 中的项目特定文件
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
回答by Karl Higley
The warning in lines 2-4 is telling you to move your plugins folder from ~/.sbt/plugins/plugins.sbt
to ~/.sbt/0.13/plugins/plugins.sbt
.
在线路警告2-4告诉你的文件夹请将您的插件~/.sbt/plugins/plugins.sbt
来~/.sbt/0.13/plugins/plugins.sbt
。
回答by Koushik Paul
Eclipse doesn't have sbt plugin, although sbt has an eclipse plugin
Eclipse 没有 sbt 插件,尽管 sbt 有一个 eclipse 插件
which is a workaround but not proper solution.
这是一种解决方法,但不是正确的解决方案。
which means eclipse doesnt understand build.sbt as it does for pom.xml or build.gradleso if we change a dependency in our eclipse project in build.sbt file, eclipse will not understand it, and will not change the dependency in the project dependencies.So you have to do the below steps everytime u modify any dependency.
这意味着eclipse 不像 pom.xml 或 build.gradle那样理解 build.sbt,所以如果我们在 build.sbt 文件中更改 eclipse 项目中的依赖项,eclipse 将无法理解它,也不会更改项目中的依赖项依赖项。因此,每次修改任何依赖项时都必须执行以下步骤。
The workaround is as follows(I used windows)
解决方法如下(我用的是windows)
Step1:Download and install sbt from https://www.scala-sbt.org/release/docs/Setup.htmlfor windows it is pretty straight forward https://piccolo.link/sbt-1.2.8.msipretty straight forward
步骤 1:从https://www.scala-sbt.org/release/docs/Setup.html下载并安装 sbt for windows 非常简单 https://piccolo.link/sbt-1.2.8.msi非常简单向前
Step2:Create a folder say D:\sbt\edge now create a build.sbt file here You can use the following as the content, change it accordingly
Step2:创建一个文件夹说 D:\sbt\edge 现在在这里创建一个 build.sbt 文件您可以使用以下内容作为内容,相应地更改它
name := "edge"
version := "0.1"
scalaVersion := "2.11.8"
val sparkVersion="2.4.0"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % sparkVersion,
"org.apache.spark" %% "spark-sql" % sparkVersion,
"org.apache.spark" %% "spark-mllib" % sparkVersion % "runtime",
"org.apache.spark" %% "spark-streaming" % sparkVersion % "provided",
"org.apache.spark" %% "spark-hive" % sparkVersion % "provided",
"org.apache.spark" %% "spark-catalyst" % sparkVersion % Test,
"org.apache.spark" %% "spark-graphx" % sparkVersion,
"org.apache.spark" %% "spark-repl" % sparkVersion % "provided",
"org.apache.spark" %% "spark-yarn" % sparkVersion,
"org.apache.spark" %% "spark-mllib-local" % sparkVersion,
//"org.apache.spark" %% "spark-streaming-kafka" % "1.6.3",
//"org.apache.spark" %% "spark-streaming-twitter" % "1.6.3",
"ch.qos.logback" % "logback-classic" % "1.1.3"
)
now create these nested folders src and main like -> D:\sbt\spark\src\main
现在创建这些嵌套文件夹 src 和 main 像 -> D:\sbt\spark\src\main
Step3:Open CMD/PowerShell go to D:\sbt\edge run "sbt package"
Step3:打开 CMD/PowerShell 到 D:\sbt\edge 运行“sbt package”
Step4:Go inside .sbt in ur home directory and in plugins folder of the correct version in my case C:\Users\xxxx.sbt\1.0\plugins if u have a plugins.sbt file already, add the following line addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")if not, create and add the line.
步骤 4:进入 .sbt 在你的主目录和正确版本的插件文件夹中,在我的情况下 C:\Users\xxxx.sbt\1.0\plugins 如果你已经有一个 plugins.sbt 文件,添加以下行addSbtPlugin(" com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")如果不是,请创建并添加该行。
Step5:Go back to CMD/PowerShell , run sbt eclipse. It will create the necessary files for eclipse project. Step6:Open an eclipse workspace, and import this project as an existing project.
第五步:回到 CMD/PowerShell ,运行 sbt eclipse。它将为 eclipse 项目创建必要的文件。 Step6:打开一个eclipse工作区,把这个工程作为已有工程导入。
回答by uvsmtid
Solution
解决方案
Simply update to the latest sbt
(sbt-0.13.9-1.noarch
in my case) using original documentation(for F23 in my case):
只需使用原始文档(在我的情况下为 F23 )更新到最新的sbt
(sbt-0.13.9-1.noarch
在我的情况下):
curl https://bintray.com/sbt/rpm/rpm \
| sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
sudo yum install --best --allowerasing sbt
And try again from the project directory (it took ~10 mins to get dependencies the first time):
并从项目目录中重试(第一次获取依赖项需要大约 10 分钟):
sbt eclipse
Original Problem
原问题
It seems like a problem of (at least ) sbt-0.13.1
on (at least) Linux.
这似乎是sbt-0.13.1
(至少)Linux 上的(至少)问题。
I used default packages on Linux F23:
我在 Linux F23 上使用了默认包:
scala-2.10.4-8.fc23.noarch
java-1.8.0-openjdk-1.8.0.91-6.b14.fc23.x86_64
sbt-0.13.1-8.fc23.noarch
scala-2.10.4-8.fc23.noarch
java-1.8.0-openjdk-1.8.0.91-6.b14.fc23.x86_64
sbt-0.13.1-8.fc23.noarch
And nopermutations ( ~/.sbt/plugins/plugins.sbt
, ~/.sbt/0.13/plugins/plugins.sbt
, PROJECT_DIR/project/plugins.sbt
, ...) with configuration options worked.
并且没有配置选项的排列 ( ~/.sbt/plugins/plugins.sbt
, ~/.sbt/0.13/plugins/plugins.sbt
, PROJECT_DIR/project/plugins.sbt
, ...) 有效。
回答by Suresh Kumar Pathak
回答by v_d123
to create your sbt project on scala eclipse you need to few things:
要在 Scala Eclipse 上创建您的 sbt 项目,您需要做几件事:
- create a new project
- add folders structure in the project
- go to the terminal, through cd command go to your project,
- type sbt, then it starts downloading, after that
- go to project see, is there any project folder made or not
- under that folder create plugin.sbt and add sbt (addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.13") addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
- then go to terminal again type compile den eclipse
- it's done, it show a success message
- 创建一个新项目
- 在项目中添加文件夹结构
- 转到终端,通过 cd 命令转到您的项目,
- 输入 sbt,然后开始下载,然后
- 去项目看看,有没有制作项目文件夹
- 在该文件夹下创建 plugin.sbt 并添加 sbt (addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.13") addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % " 5.2.4")
- 然后再次进入终端输入 compile den eclipse
- 完成,显示成功信息
回答by Kuba Anonim
I was able to get rid of same error by downgrading sbteclipse-plugin form 4.0 to 2.5.0
通过将 sbteclipse-plugin 表单 4.0 降级到 2.5.0,我能够摆脱同样的错误