sbt项目

时间:2016-06-06 23:43:32

标签: java scala sbt noclassdeffounderror classnotfoundexception

对于我来说my scala build tool project的生活充满了ClassNotFoundExceptions。

我所要做的就是克隆它并做sbt run而我得到

java.lang.NoClassDefFoundError: com/example/Utils$$anonfun$1
        at com.example.Utils$.shortenTypeSignature(Utils.scala:10)
        at com.example.Hello$.getTypedDeclaration$1(Hello.scala:69)
        at com.example.Hello$.iterateThroughSourceFile$1(Hello.scala:113)
        at com.example.Hello$.main(Hello.scala:157)
        at com.example.Hello.main(Hello.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
Caused by: java.lang.ClassNotFoundException: com.example.Utils$$anonfun$1
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at com.example.Utils$.shortenTypeSignature(Utils.scala:10)
        at com.example.Hello$.getTypedDeclaration$1(Hello.scala:69)
        at com.example.Hello$.iterateThroughSourceFile$1(Hello.scala:113)

以前,我必须在Hello.scala中插入GlobFinder类型的变量,否则我会得到:

/*
Exception in thread "main" java.lang.NoClassDefFoundError: info/collaboration_station/utilities/GlobFinder
  at info.collaboration_station.utilities.FileFinder.tryFindAbsolutePathOfFileWhoseNameIs(FileFinder.java:128)
  at com.example.Hello$.main(Hello.scala:137)
  at com.example.Hello.main(Hello.scala)
Caused by: java.lang.ClassNotFoundException: info.collaboration_station.utilities.GlobFinder
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 3 more
 */

修复是添加此行...

val vvv = new GlobFinder("foo")

为什么my Scala project如此充满ClassNotFoundExceptions?

1 个答案:

答案 0 :(得分:0)

我想我明白了。该项目正在运行clean。它必须删除自己的类文件。

话虽如此,从

中移除clean

val proc = Runtime.getRuntime.exec(Array[String]("sbt", "clean", "set scalacOptions in ThisBuild ++= Seq(\"-print\")", "compile", "exit"))

Hello.scala中的

^没有解决任何问题。