Creating Scala Project with Eclipse, sbteclipse -- directory layout

3.9k views Asked by At

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?

3

There are 3 answers

2
Garrett Hall On BEST ANSWER

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

0
Daniel C. Sobral On

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.

0
zduny On

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.