My projects is running on a Windows 2008 Server.
My project source code sit in the following folders:
com.company.division.dao
com.company.division.entity
com.company.division.main
com.company.division.junit
My junit test class are in the folder C:\Sample\com\company\division\junit. I am using JUnit 4.11
When I run this from Eclipse it runs fine.
I have tried the following from DOS command line:
First I cd C:\Sample\com\company\division\junit\
From C:\Sample\com\company\division\junit> where the compiled EventTests.class file exists I run:
java -classpath "C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
OR
java -cp "C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
OR
java -cp ".;C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
But nothing seems to work. I get an exception:
JUnit version 4.11
Could not find class: com.company.division.junit.EventTests
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
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$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 18 more
So from one of the other threads I figured out what the command eclipse was using to run the unit tests. Eclipse was using javaw.exe, I replaced javaw with java.exe tool. Here is the command,
C:\Java\64bit_Browser_Plugin\bin\java.exe -Dfile.encoding=Cp1252 -classpath C:\working_dir\bin;C:\working_dir\lib\mysql-connector-java-5.0.8-bin.jar;C:\working_dir\lib\ojdbc14.jar;C:\working_dir\lib\spring-beans-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-context-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-core-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-expression-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-jdbc-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-tx-3.2.4.RELEASE.jar;C:\working_dir\lib\commons-logging-1.1.3.jar;C:\working_dir\lib\nzjdbc.jar;C:\working_dir\lib\junit.jar;C:\working_dir\lib\spring-batch-core-2.2.5.RELEASE.jar;C:\working_dir\lib\spring-batch-infrastructure-2.2.5.RELEASE.jar;C:\working_dir\lib\hamcrest-core-1.3.jar;C:\working_dir\lib\log4j-1.2.14.jar;C:\working_dir\lib\mail.jar;C:\working_dir\lib\spring-context-support-4.0.1.RELEASE.jar;/C:/eclipse/configuration/org.eclipse.osgi/bundles/167/1/.cp/;/C:/eclipse/configuration/org.eclipse.osgi/bundles/166/1/.cp/ org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 54536 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames com.omnitracs.fra.junit.EventTests
I am still getting an exception:
Could not connect to: : 54536
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(Remote
TestRunner.java:570)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTest
Runner.java:381)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTes
tRunner.java:197)
What am I missing?
Try including hamcrest-core.jar in the classpath.
https://github.com/junit-team/junit/wiki/Download-and-Install
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments