如何让 Eclipse 识别来自 SBT 的依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9070336/
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 have Eclipse recognize dependencies from SBT
提问by chiappone
I am trying to figure out how to make Eclipse recognize dependencies that are retrieved using SBT? SBT download the correct dependencies and puts them in my ~/.ivy directory but eclipse doesn't see them. Is there a way to do this?
我想弄清楚如何让 Eclipse 识别使用 SBT 检索的依赖项?SBT 下载正确的依赖项并将它们放在我的 ~/.ivy 目录中,但 eclipse 看不到它们。有没有办法做到这一点?
thanks
谢谢
采纳答案by Andrew
This is probably not the answer you are looking for and I admit it is not elegant but it currently works for me, meaning that I think it takes less time for me to periodically do the following instead of researching and finding a more elegant solution.
这可能不是您正在寻找的答案,我承认它并不优雅,但目前对我有用,这意味着我认为我需要更少的时间定期执行以下操作,而不是研究和找到更优雅的解决方案。
I assume you are using the sbt-eclipse plugin ( https://github.com/typesafehub/sbteclipse). When I add new dependencies to my project ( which is actually pretty rare ) I simply regenerate my eclipse project files from the plugin. The downside of this is that I have a multiple module project and after I refresh the projects in eclipse I need to re-add the inter-project dependencies in the eclipse build path editor.
我假设您正在使用 sbt-eclipse 插件(https://github.com/typesafehub/sbteclipse)。当我向我的项目添加新的依赖项时(这实际上非常罕见),我只需从插件重新生成我的 eclipse 项目文件。这样做的缺点是我有一个多模块项目,在 eclipse 中刷新项目后,我需要在 eclipse 构建路径编辑器中重新添加项目间依赖项。
Like I mentioned it is pretty hacky but all in all I really don't loose that much time doing it. It's not pretty but it works.
就像我提到的那样,它非常笨拙,但总而言之,我真的没有浪费那么多时间来做这件事。它不漂亮,但它有效。
Best of luck, Andy
祝你好运,安迪
回答by Arty
If you are using sbteclipse plugin it's achievable in a simple way. In sbt type:
如果您使用的是 sbteclipse 插件,则可以通过简单的方式实现。在 sbt 类型中:
reload
eclipse with-source=true
使用-source
=true重新加载eclipse
Then in eclipse, hit F5 on a project folder to refresh it. Or right-click and choose "Refresh". Just works.
然后在 Eclipse 中,在项目文件夹上按 F5 以刷新它。或右键单击并选择“刷新”。只是工作。
回答by cathalmcginley
I use the Apache IvyDEplugin for Eclipse, and I've had more luck with this approach. It's only described in the old sbt docs, but works with sbt 0.11
我为 Eclipse使用了Apache IvyDE插件,而且我对这种方法的运气更好。它仅在旧的 sbt 文档中描述,但适用于 sbt 0.11
First, install the IvyDE plugin in Eclipse and restart.
首先,在 Eclipse 中安装 IvyDE 插件并重新启动。
Run the sbt command deliver-local
- this will create an XML ivy file of your dependencies.
运行 sbt 命令deliver-local
- 这将创建依赖项的 XML ivy 文件。
In Eclipse, under your Project/Properties - Java Build Path - Libraries, click "Add Library" and choose "IvyDE Managed Dependencies" then select the file target/scala-2.9.1/ivy-projectversion.xml
在 Eclipse 中,在您的 Project/Properties - Java Build Path - Libraries 下,单击“Add Library”并选择“IvyDE Managed Dependencies”,然后选择文件 target/scala-2.9.1/ ivy- projectversion.xml
When you add a new dependency to build.sbt, run the sbt commands reload
and deliver-local
again. Then right-click the Ivy library for your project in the Package Explorer - it will be called "target/scala-2.9.1/ivy-projectversion.xml [compile,test]", and click the second "Refresh" menu item (between "Refresh" and "Reload Settings" - not"F5 Refresh" ).
当您添加新的依赖于build.sbt,运行SBT命令reload
和deliver-local
试。然后在 Package Explorer 中右键单击您项目的 Ivy 库 - 它将被称为“target/scala-2.9.1/ ivy- projectversion.xml [compile,test]”,然后单击第二个“Refresh”菜单项( “刷新”和“重新加载设置”之间 -不是“F5刷新”)。
回答by aspdeepak
In command prompt go to the project folder and type
在命令提示符下转到项目文件夹并键入
sbt eclipse
This should generate the appropriate .classpathentries in eclipse project.
这应该会在 eclipse 项目中生成适当的.classpath条目。
Go back to eclipse, select the project and press f5, this will reload the referenced libs.
返回 eclipse,选择项目并按 f5,这将重新加载引用的库。
回答by freedev
All you need is execute from your project home:
您所需要的只是从您的项目主页执行:
sbt "eclipse with-source=true"
or enter sbt
console and write:
或输入sbt
控制台并写入:
eclipse with-source=true
BTW: I don't know if from Jan '12 something has changed but now it seems much more simple.
顺便说一句:我不知道从 12 年 1 月开始是否发生了一些变化,但现在看起来更简单了。
回答by FreewheelNat
The following works for me:
以下对我有用:
1) close project in Eclipse
1)在Eclipse中关闭项目
2) in my file explorer, browse to my Eclipse project, make sure hidden files are visible
2) 在我的文件资源管理器中,浏览到我的 Eclipse 项目,确保隐藏文件可见
3) open .classpath in a simple text editor
3) 在简单的文本编辑器中打开 .classpath
4) copy the bottom entry. For example, in my current project, it is <classpathentry path="/home/natalie/.ivy2/cache/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-1.8.jar" kind="lib"></classpathentry>
4)复制底部条目。例如,在我当前的项目中,它是<classpathentry path="/home/natalie/.ivy2/cache/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-1.8.jar" kind="lib"></classpathentry>
5) navigate to my .ivy folder, cache, then down to the library I have added via sbt
5)导航到我的 .ivy 文件夹,缓存,然后到我通过 sbt 添加的库
6) right click on jar file, select properties, copy the path and jar file name and replace it in the entry I copied in step 4
6)右键jar文件,选择属性,复制路径和jar文件名,替换到我在第4步复制的条目中
7) save .classpath
7)保存.classpath
8) open my project on Eclipse
8) 在 Eclipse 上打开我的项目
New dependency is now available in Eclipse.
新的依赖项现在在 Eclipse 中可用。