0

I have the following folder structure

base directory = "."
build directory (for classes) = "./build/classes"
build directory (for test classes) = "./build/test/classes"
source = "./src"
test = "./test"
test_libraries = "./test_libraries"

everything works fine When I am running the test files with the command

java -cp /usr/share/java/junit4-4.11.jar:build/classes:build/test/classes/ org.junit.runner.JUnitCore myclass.MyClassTest

but when I change the location of the juint file to test_libraries/junit4-4.44.jar and I run the command

java -cp ./test_libraries/junit4-4.11.jar:build/classes:build/test/classes/ org.junit.runner.JUnitCore myclass.MyClassTest

I get the following errors

Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:75)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
isnvi23h4
  • 1,910
  • 1
  • 27
  • 45
  • but why then there is no error when I am using /usr/share/java/junit-version? – isnvi23h4 Jul 27 '15 at 19:45
  • How was the /usr/share version installed? I'm guessing whatever method it did a repacked jar with the dependencies in it, while the other you downloaded just junit jar file, and not its dependencies. Look at the classes contained in each. – Larry Shatzer Jul 27 '15 at 19:48

2 Answers2

1

You need Hamcrest on your classpath.

hd1
  • 33,938
  • 5
  • 80
  • 91
0

You are missing Hamcrest Jar

http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar

JUnit depends on Hamcrest for a lot of methods.

SnakeDoc
  • 13,611
  • 17
  • 65
  • 97