Creating Scala Project with Eclipse, sbteclipse -- directory layout
Asked Answered
W

3

5

I am trying to use Eclipse as my IDE, and I have installed sbt as build tool and sbteclipse as build tool plugin for Eclipse. I followed a sbteclipse tutorial http://www.atsnippets.com/development/starting-with-simple-build-tool-sbt-for-scala.html to make my directory structure look like the following:

HelloWorld
     \- src
          \-main
              \-scala
              \-java
          \-test 
              \scala
              \java
     \target
          \-scala-2.9.1
          \-streams

Now, I want to use Eclipse as my editor (I like its checking, auto-completion and etc.). However, I do not know how to make Eclipse understand the above directory layout (I can't import the above directory as my project, or I did not find the right way to do so). Can someone share the experience?

I tried another way to start my toy project then: I used Eclipse to create a scala project. However, the directory structure is not what I wanted either. Here is my directory result by "New Scala Project", "New Package (com.foo.hello)" operation

HelloWorld
   \-src
       \-com
           \-foo
               \-hello

This is not what I wanted either, because I want to separate main from test. Any recommended way?

Worship answered 16/5, 2012 at 14:29 Comment(1)
You've tried File > Import > General > Existing Projects into Workspace?Bywoods
S
9

Create the directory structure you want under the HelloWorld project through Right-click -> New... -> Folder. Then on the main and test folders Right-click -> Build Path -> Use as Source Folder

Salvatoresalvay answered 16/5, 2012 at 14:48 Comment(2)
are you suggesting not using stbeclipse?Worship
I haven't used sbt, but the open-source Scala IDE by Martin Odersky (creator of Scala) has been the only Scala plug-in I've needed.Salvatoresalvay
Y
3

SBT Eclipse should generate a project file with everything correctly set up. You do need to run "sbt update" after any build file change, and then regenerate the eclipse project file. I suspect this might have been your problem.

It should generate two files, .project and .classpath, like these:

<projectDescription>
  <name>default-0d85ea</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>
</projectDescription>

and

<classpath>
  <classpathentry output="target/scala-2.9.2/classes" path="src/main/scala" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/classes" path="src/main/java" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/test-classes" path="src/test/scala" kind="src"></classpathentry>
  <classpathentry output="target/scala-2.9.2/test-classes" path="src/test/java" kind="src"></classpathentry>
  <classpathentry path="org.scala-ide.sdt.launching.SCALA_CONTAINER" kind="con"></classpathentry>
  <classpathentry path="/home/dcs/.ivy2/cache/org.scalacheck/scalacheck_2.9.2/jars/scalacheck_2.9.2-1.9.jar" kind="lib"></classpathentry>
  <classpathentry path="/home/dcs/.ivy2/cache/org.scala-tools.testing/test-interface/jars/test-interface-0.5.jar" kind="lib"></classpathentry>
  <classpathentry path="/home/dcs/.ivy2/cache/org.scala-lang/scala-swing/jars/scala-swing-2.9.2.jar" kind="lib"></classpathentry>
  <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry>
  <classpathentry path="bin" kind="output"></classpathentry>
</classpath>

Note in the latter file that src/main/scala and src/main/java are added as src entries.

Yeah answered 16/5, 2012 at 21:1 Comment(0)
E
0

Try creating empty project and add folders manually (right-click on project New->Folder). Then set-up builder in project properties and (optionally) create run configuration.

Engrave answered 16/5, 2012 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.