Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala eclipse plugin java.lang.ClassNotFoundException

I am using eclipse Version: 3.7.2 with the Scala IDE for Eclipse 2.1.0.nightly-2_09-201203121521-6e8582e. The java version is 1.6.0_31. The OS is Ubuntu 11.10.

I have looked for solutions to this problem, but I have not found one yet. I hope there is not an obvious answer that I have missed.

I have this class (note the package):

package model.x.y

import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class GibberishTestSuite extends FunSuite {
  test("Check Gibberish") {
    assert("blah" === "blah")
  }
}

I am also using gradle and the source path looks like this (note that the package does not match the directory hierarchy):

.../src/test/scala/model/GibberishTest.scala

Eclipse and gradle generate the coresponding class files:

bin/model/x/y/GibberishTestSuite.class
build/classes/test/model/x/y/GibberishTestSuite.class

This runs fine through gradle, but when I try to run in eclipse, I get

Class not found model.GibberishTestSuite
java.lang.ClassNotFoundException: model.GibberishTestSuite
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)

If I change the package to

package model

so that the directory hierarchy and the package name match, then I am able to run the unit test in eclipse. In scala, it is legal for the package structure and the directory structure not to match. However, the mismatch seems to be confusing eclipse or the plugin.

Am I doing something wrong? Am I missing some configuration nuance? Is this scala language feature not supported in eclipse? Will it be supported at some point?

Thank you.

like image 489
Julio Garcia Avatar asked Mar 13 '12 14:03

Julio Garcia


1 Answers

This is an Eclipse (JDT) problem rather than a Scala/scala-ide problem.

There was a bug raised against Eclipse (Package Explorer tree does match declared package), but basically, Eclipse assumes that the hierarchy matches the package names. This will be fixed eventually in the Scala-ide, but the model needs to be changed, to remove the dependency on the JDT. If you want this fixed, it's a good idea to add your vote to the above issue.

like image 54
Matthew Farwell Avatar answered Oct 22 '22 04:10

Matthew Farwell