Issue
When I try to run a junit test in eclipse on a project which is created with gradle I get the following error in the eclipse console
Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
Caused by: java.lang.ClassNotFoundException: org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
If I run the same test from the command line using
gradle test
it works fine.
Also I noticed that if I remove the following two dependencies:
testImplementation group: 'org.apache.tomee', name: 'openejb-cxf-rs', version: '8.0.0'
testImplementation group: 'org.apache.tomee', name: 'arquillian-tomee-embedded', version: '8.0.0'
the tests can be started in Eclipse. Obviously the tests fail at some point because of the missing dependencies.
Looks like this is some kind of weird conflict going on in Eclipse. Also it was working fine before the December update of Eclipse.
For completeness here the versions:
- gradle 6.0.1
- Eclipse 2019-12 (4.14.0)
- Jdk 11
- Junit 4.12
Today I also tried to install an older version of Eclipse (2019-09) and there with the same setup I could just run the tests.
Also I noticed the following. If I go to Run->Run Configurations, select my test runner and "Show command line" I notice that when things are not working the classpath is written in a file, whereas when it is working it is just written as command line arguments.
So the following is not working:
C:\Program Files\Java\jdk-11.0.4\bin\javaw.exe -ea -Dfile.encoding=Cp1252 "@C:\projects\provisioning-service\provisioning-service-resource\.temp-ExampleTest-classpath-arg-1578480407549.txt" org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 58388 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames com.xelion.provisioning.resource.ExampleTest
The following is
C:\Program Files\Java\jdk-11.0.4\bin\javaw.exe -ea -Dfile.encoding=Cp1252 -classpath "C:\projects\provisioning-service\provisioning-service-resource\target\bin;...manymorehere" org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 58412 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames com.xelion.provisioning.resource.ExampleTest
So the main difference seems to be that in the first case the classpath is evaluated from the file
C:\projects\provisioning-service\provisioning-service-resource\.temp-ExampleTest-classpath-arg-1578480407549.txt
and in the second case it is written out
-classpath "C:\projects\provisioning-service\provisioning-service-resource\target\bin;...
Solution
Looks like an Eclipse bug, see here for details
https://bugs.eclipse.org/bugs/show_bug.cgi?id=558495
I added the following download side
https://download.eclipse.org/eclipse/updates/4.15-I-builds/I20200105-1800/
and updated "Eclipse Java Development Tools"
This solved the issue.
Answered By - finrod
Answer Checked By - David Marino (JavaFixing Volunteer)