Question

I tried to run junit4 test case from command line using:

java -cp junit-4.8.1.jar;test\Dijkstra;test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00

but I got the following error:

java.lang.NoClassDefFoundError: graph/shortestgraphpath;

while the test case is working without any problems in eclipse.

Hint: in eclipse, shortestgraphpath was added in Referenced Libraries.

Was it helpful?

Solution

You need to the jar file containing shortestgraphpath to java class path.

java -cp junit-4.8.1.jar;test\Dijkstra; test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00

The class path is the value that you pass to java with -cp so in your question you just supply junitand your compiled classes. Try updating it with the jar file with the missing class.

 java -cp junit-4.8.1.jar;<path to jar file>;test\Dijkstra;test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00

You might have to add additional jar files as well. I recommend that you take a look at some build tool to help you build and run your java applications for example Maven, Gradle, Buildr.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top