ClassNotFoundException:从命令行运行时的spark.Request

时间:2017-10-20 07:14:17

标签: java spark-java

在此处关注教程:http://sparkjava.com/

我下载了spark-core然后编译了这个类:

import static spark.Spark.*;

public class Main {
    public static void main(String[] args) {
        get("/hello", (req, res) -> "hello world");
    }
}

$ javac -classpath ~/Downloads/spark-core-2.6.0.jar Main.java

并在运行时:

$ java -cp "~/Downloads/spark-core-2.6.0.jar:." Main


Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: spark/Request
    at Main.main(Main.java:5)
Caused by: java.lang.NoClassDefFoundError: spark/Request
    ... 1 more
Caused by: java.lang.ClassNotFoundException: spark.Request
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

我做错了什么?

1 个答案:

答案 0 :(得分:1)

将引号留在类路径周围:

$ java -cp ~/Downloads/spark-core-2.6.0.jar:. Main.

如果你这样做,你会收到org/slf4j/LoggerFactory未找到的错误,除非你下载它并将其包含在类路径中,否则确实会丢失。