Kafka scalaConsole具有ClassNotFoundException

时间:2014-04-17 12:46:40

标签: scala apache-kafka

从gradlew启动scalaConsole时,在类路径中找不到主Scala运行器:

05:21:45/kafka-0.8.1-src:43 $./gradlew scalaConsole
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
Building project 'core' with Scala version 2.8.0
Building project 'perf' with Scala version 2.8.0
:core:compileJava UP-TO-DATE
:core:compileScala UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:scalaConsole
Exception in thread "main" java.lang.NoClassDefFoundError: scala/tools/nsc/MainGenericRunner
Caused by: java.lang.ClassNotFoundException: scala.tools.nsc.MainGenericRunner
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
:core:scalaConsole FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:scalaConsole'.
> Process 'command '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

1 个答案:

答案 0 :(得分:1)

http://sethrylan.org/2013/07/02/scala-gradle-scalaconsole.html开始,尝试将编译器添加到运行时依赖项中。

dependencies {
  runtime "org.scala-lang:scala-compiler:2.10.4"
  compile "org.scala-lang:scala-library:2.10.4"
}

同一篇文章建议使用Gradle的-q选项启动它:

$ gradle scalaConsole -q

请注意,我不认为这是一个非常好的解决方案,因为您真的不想让您的代码依赖于编译器,但至少它是一种解决方法。