timaschew timaschew - 2 months ago 12
Scala Question

Suggest imports does not work with Scala IDE (and sbt)

I had several issues setting up Scala and Eclipse with auto import suggestions. I can run (compile and run) simple Scala code. But I need the auto/suggest import feature.

My first attempt was to use an existing Eclipse (Version: Neon.2 Release (4.6.2)) and install Scala via update site. Installation was done, but my JRE could not be detected. Pointing to my directory where

is located and also their parents didn't work, Eclipse didn't recognize it as a valid JRE root.

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

So I decided to download a Scala IDE from http://scala-ide.org/ (Build id: 4.5.0-vfinal-2016-12-13T10:59:29Z-Typesafe)

I've already installed scala (2.12.2) via homebrew but I read that Scala IDE comes with their own Scala version (2.10 and 2.11), so this should not be an issue.

I've tried to follow this tutorial to setup a simple Akka app, even if it's a bit outdated I gave it a try: http://doc.akka.io/docs/akka/1.3.1/intro/getting-started-first-scala-eclipse.html

Of course I installed newer version of Akka (akka_2.11-2.4.18.zip) and tried to add the akka-actor.jar as external jar.
When trying to use the
class inside of a Scala class file, it shows me errors that the class cannot be found. Clicking on the red x doesn't show me a solution, I need to write the import line by hand.
My question is exactly about how to configure my setup that Eclipse show me the solution to import the proper class automatically.

I've tried to setup the project with sbt (0.13) and sbteclipse. I did the setup how it's explained here: How to add a scala library to eclipse and added Akka as dependency.
It installed lot of stuff (saw lot of output in the terminal) and I used
Import existing project
in Eclipse, but still the auto import doesn't work. If I open the properties and navigate to Java Build Path, it looks fine, I mean no errors or warnings.

This is what it shows me:enter image description here

Actually the line is hidden be the popup, it's just this line:

class Worker extends Actor {

My .project file:

<name>My Project</name>
<linkedResources> </linkedResources>

My build.sbt file:

name := "My Project"

version := "1.0"

scalaVersion := "2.11.11"

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

My .classpath file:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<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!/"/>
<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">
<attribute name="javadoc_location" value="jar:file:/Users/timaschew/.ivy2/cache/com.typesafe/config/docs/config-1.3.1-javadoc.jar!/"/>
<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">
<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!/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>


It seems that Eclipse is not a really good choice for Scala developing.

I switched to IntelliJ. Scala can be installed at the very first usage of IntelliJ and it supports sbt as well. Change in the build.sbt file are recognized by IntelliJ to trigger sbt (to install new dependencies for instance).

And of course suggesting to import some packages for usage of unkown classes are also working fine.

It also allows you to install different versions of Scala very easy.