Scala eclipse plugin java.lang.ClassNotFoundException
Asked Answered
G

1

9

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.

Gneiss answered 13/3, 2012 at 14:55 Comment(1)
I've noticed the same thing. I've assumed it just isn't supported by the Eclipse build.Isomeric
H
7

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.

Hadst answered 13/3, 2012 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.