0

I'm a newbie to Java (just two days) and am trying to get an HTTP server running using Spark. I created a new Maven project in IntelliJ and have a Hello World response coming back from Spark when running it in IntelliJ. As a learning exercise, I would like to get the app running from the command line using Java.exe. When I run java Main, I get the following error:

Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDef oundError: 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(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

Looks like it can't find the Spark .jar files. There's a command line option -cp to specify paths to dependencies. After looking up where Maven keeps these files, I tried running:

java -cp .;C:\Users\jbuschmann.m2\repository Main

Still same error. How do I specify the path to the Maven dependencies?

Joe B
  • 873
  • 1
  • 9
  • 17
  • 1
    You could run `mvn exec:java -Dexec.mainClass="com.example.Main"`. See for example: http://stackoverflow.com/questions/9846046/run-main-class-of-maven-project – assylias Oct 16 '15 at 16:21
  • see also https://maven.apache.org/plugins/maven-dependency-plugin/build-classpath-mojo.html –  Oct 16 '15 at 16:22

1 Answers1

0

Instead of giving the repository in the -classpath, try adding the location of your spark.jar.

java -cp \path\to\spark.jar Main
Sharath Bhaskara
  • 467
  • 6
  • 12