vrepsys
vrepsys

Reputation: 2213

Running tests in IntelliJ ClassNotFoundException

I tried many different run configs, but whatever I do I get this exception when running specs2 tests in IntelliJ for scala.

It always fails to find a class that ends with a $ sign. I checked - and there really is no such class file. There's AppControllerIT.class and lots of classes like AppControllerIT$innerFunctionOrclass.clas, but not AppControllerIT$.class

Any ideas?

Thanks!

com.haha.market.api.e2e.controllers.AppControllerIT$

java.lang.ClassNotFoundException: com.haha.market.api.e2e.controllers.AppControllerIT$


STACKTRACE
  java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  org.specs2.reflect.Classes$$anonfun$loadClassEither$1.apply(Classes.scala:140)
  org.specs2.reflect.Classes$$anonfun$loadClassEither$1.apply(Classes.scala:140)
  org.specs2.control.ActionT$$anonfun$safe$1.apply(ActionT.scala:89)
  org.specs2.control.ActionT$$anonfun$reader$1$$anonfun$apply$6.apply(ActionT.scala:80)
  org.specs2.control.Status$.safe(Status.scala:100)

Upvotes: 4

Views: 1510

Answers (1)

marios
marios

Reputation: 8996

Classes with $ signs at the end are generate from compiled Scala objects. This means you may have an object defined similar to this:

package com.haha.market.api.e2e.controllers

object AppControllerIT {
}

From your error, it seems that an older compiled artifact or a library (?) is polluting your classpath. First, try cleaning up the project (mvn clean or sbt clean). Next, try to clean any libraries you have in your project inside IntelliJ. IntelliJ sometimes caches multiple versions of the same libraries which may cause confusion during runtime. To clean those up go to "File -> Project Structure" in IntelliJ and manually delete any duplicated libraries you may have.

Upvotes: 1

Related Questions