首页 文章

建议导入不适用于Scala IDE(和sbt)

提问于
浏览
0

我在使用自动导入建议设置Scala和Eclipse时遇到了一些问题 . 我可以运行(编译和运行)简单的Scala代码 . 但我需要自动/建议导入功能 .

我的第一次尝试是使用现有的Eclipse(Version:Neon.2 Release(4.6.2))并通过更新站点安装Scala . 安装已完成,但无法检测到我的JRE . 指向 javac 所在的目录,他们的父母也没有将它识别为有效的JRE根目录 .

/usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac

所以我决定从http://scala-ide.org/下载一个Scala IDE(Build id:4.5.0-vfinal-2016-12-13T10:59:29Z-Typesafe)

我已经通过自制软件安装了scala(2.12.2),但我读到Scala IDE附带了自己的Scala版本(2.10和2.11),所以这应该不是问题 .

我've tried to follow this tutorial to setup a simple Akka app, even if it'有点过时我试了一下:http://doc.akka.io/docs/akka/1.3.1/intro/getting-started-first-scala-eclipse.html

当然我安装了较新版本的Akka(akka_2.11-2.4.18.zip),并试图将akka-actor.jar添加为外部jar . 当尝试在Scala类文件中使用 Worker 类时,它会向我显示无法找到该类的错误 . 点击红色x并没有向我显示解决方案,我需要手动编写导入行 . 我的问题正是关于如何配置我的设置,Eclipse向我展示了自动导入正确类的解决方案 .

我在这里解释了've tried to setup the project with sbt (0.13) and sbteclipse. I did the setup how it':How to add a scala library to eclipse并将Akka添加为依赖 . 它安装了很多东西(在终端中看到很多输出),我在Eclipse中使用了 Import existing project ,但仍然无法自动导入 . 如果我打开属性并导航到Java Build Path,它看起来很好,我的意思是没有错误或警告 .

这就是它告诉我的:
enter image description here

实际上这行是隐藏的弹出窗口,它只是这一行:

class Worker extends Actor {

我的.project文件:

<projectDescription>
  <name>My Project</name>
  <buildSpec>
    <buildCommand>
      <name>org.scala-ide.sdt.core.scalabuilder</name>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>org.scala-ide.sdt.core.scalanature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
  <linkedResources> </linkedResources>
</projectDescription>

我的build.sbt文件:

name := "My Project"

version := "1.0"

scalaVersion := "2.11.11"

libraryDependencies +=
  "com.typesafe.akka" %% "akka-actor" % "2.5.1"

我的.classpath文件:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="foo.bar"/>
    <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
    <classpathentry kind="lib" path="/Users/timaschew/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/jars/akka-actor_2.11-2.5.1.jar" sourcepath="/Users/timaschew/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/srcs/akka-actor_2.11-2.5.1-sources.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/Users/timaschew/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/docs/akka-actor_2.11-2.5.1-javadoc.jar!/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Users/timaschew/.ivy2/cache/com.typesafe/config/bundles/config-1.3.1.jar" sourcepath="/Users/timaschew/.ivy2/cache/com.typesafe/config/srcs/config-1.3.1-sources.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/Users/timaschew/.ivy2/cache/com.typesafe/config/docs/config-1.3.1-javadoc.jar!/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Users/timaschew/.ivy2/cache/org.scala-lang.modules/scala-java8-compat_2.11/bundles/scala-java8-compat_2.11-0.7.0.jar" sourcepath="/Users/timaschew/.ivy2/cache/org.scala-lang.modules/scala-java8-compat_2.11/srcs/scala-java8-compat_2.11-0.7.0-sources.jar">
        <attributes>
            <attribute name="javadoc_location" value="jar:file:/Users/timaschew/.ivy2/cache/org.scala-lang.modules/scala-java8-compat_2.11/docs/scala-java8-compat_2.11-0.7.0-javadoc.jar!/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

1 回答

  • 0

    似乎Eclipse不是Scala开发的真正好选择 .

    我切换到IntelliJ . Scala可以在IntelliJ的第一次使用时安装,它也支持sbt . IntelliJ可识别build.sbt文件中的更改以触发sbt(例如,安装新的依赖项) .

    当然,建议导入一些使用未知类的包也可以正常工作 .

    它还允许您非常轻松地安装不同版本的Scala .

相关问题