Tuesday, October 9, 2012

Mixed Java and Scala development in Eclipse

.classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.inter
nal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

.project file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>testScala</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.scala-ide.sdt.core.scalabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.scala-ide.sdt.core.scalanature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>


TestPerson.scala class
package dave

object  TestPerson {
  def main(args: Array[String]) {
    val person = new Person("dave")

    println(person)
  }
}

Person.java class
package dave;

public class Person {
    
    String name;
    
    public Person() {}
    
    
    public Person(String name) {
        this.name= name;
    }
    
    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    @Override
    public String toString() {
        return "Person [name=" + name + "]";
    }

    
    
}
Eclipse with Scala plugin
Java buildpath
All files in project
[dave@dave testScala]$ ls -lRa
.:
total 32
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:04 ..
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 bin
-rw-rw-r--. 1 dave dave 2222 Oct  9 22:51 .cache
-rw-rw-r--. 1 dave dave  376 Oct  9 22:04 .classpath
-rw-rw-r--. 1 dave dave  425 Oct  9 22:04 .project
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:40 .settings
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 src

./bin:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:51 dave

./bin/dave:
total 20
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:51 .
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:41 ..
-rw-rw-r--. 1 dave dave  821 Oct  9 22:41 Person.class
-rw-rw-r--. 1 dave dave  648 Oct  9 22:51 TestPerson.class
-rw-rw-r--. 1 dave dave  706 Oct  9 22:51 TestPerson$.class

./.settings:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:40 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
-rw-rw-r--. 1 dave dave  587 Oct  9 22:04 org.eclipse.jdt.core.prefs
-rw-rw-r--. 1 dave dave  847 Oct  9 22:40 org.scala-ide.sdt.core.prefs

./src:
total 12
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 .
drwxrwxr-x. 5 dave dave 4096 Oct  9 22:41 ..
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:20 dave

./src/dave:
total 16
drwxrwxr-x. 2 dave dave 4096 Oct  9 22:20 .
drwxrwxr-x. 3 dave dave 4096 Oct  9 22:04 ..
-rw-rw-r--. 1 dave dave  328 Oct  9 22:25 Person.java
-rw-rw-r--. 1 dave dave  131 Oct  9 22:51 TestPerson.scala
[dave@dave testScala]$ 

No comments:

Post a Comment