Jas
Jas

Reputation: 15103

ClassNotFoundException: spark.Request when running from command line

Was following tutorial here: http://sparkjava.com/

I downloaded spark-core then compiled this class:

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

and when running:

$ 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

What did i do wrong?

Upvotes: 1

Views: 1191

Answers (1)

cello
cello

Reputation: 5486

Leave the quotes around the class path away:

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

If you do that, you'll get an error that org/slf4j/LoggerFactory is not found, which is indeed missing unless you download it as well and include it in the class path.

Upvotes: 2

Related Questions