为什么在尝试运行此代码时出现java.lang.NoClassDefFoundError? [英] Why do I get java.lang.NoClassDefFoundError when I trying to run this code?

查看:90
本文介绍了为什么在尝试运行此代码时出现java.lang.NoClassDefFoundError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想映射字符串中的字符,但遇到运行时错误。

I want to map over the characters in a string, but I'm getting runtime errors.

示例:

object Hello {
    def hello(c: Char) {
        print(c)
    }

    def main(args: Array[String]) {
        "Hello World!".map(hello)
    }
}

跟踪:

scalac Hello.scala
java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: scala/LowPriorityImplicits
    at Hello.main(Hello.scala)
Caused by: java.lang.ClassNotFoundException: scala.LowPriorityImplicits
    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)
    ... 1 more
make: *** [test] Error 1


推荐答案

我认为您的问题是scala库不在您的运行时类路径中。您必须手动手动添加。

I think that your problem is that scala library is not in your runtime classpath. you must manually add manually.

如果您使用的是maven或sbt之类的工具,则依赖项可能会标记为已提供,而不是已编译。

If you are using tools like maven or sbt, maybe the dependency is marked as provided instead compiled.

如果不使用这些工具,请将 scala-library.jar添加到库目录中

If you are not using these tools, add "scala-library.jar" to your library directory

这篇关于为什么在尝试运行此代码时出现java.lang.NoClassDefFoundError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆