title: Eclipse Junit: java.lang.ClassNotFoundException
body: <p>I have the following problem:</p>
  
  <p>I have a java project that uses gradle. The project structure is:</p>
  
  <pre><code>src
  - main
  -- java
  -- resources
  - test
  -- java
  -- resources
  </code></pre>
  
  <p>I have the following test class:</p>
  
  <pre><code>package it.main.tests;
  
  import static org.junit.Assert.assertEquals;
  
  import org.junit.Test;
  
  public class MainTest {
  
      @Test
      public void mainTests() {
          String s = "ciao";
  
          assertEquals(s, "ciao");
      }
  }
  </code></pre>
  
  <p>If I run the following command: <strong>gradle test</strong> everything is ok. If I try to run the <strong>mainTests</strong> method from eclipse (right click on the method, Run As, JUnit test) I have the following exception:</p>
  
  <pre><code>Class not found it.main.tests.MainTest
  java.lang.ClassNotFoundException: it.main.tests.MainTest
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:770)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:499)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
  </code></pre>
  
  <p>This is the <strong>build.gradle</strong> file:</p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'war'
  
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
      jcenter()
  }
  
  compileJava {
      options.fork = true
  }
  
  dependencies {
      // Add all the jar dependencies from the lib folder. 
      compile fileTree(dir: 'src/main/webapp/WEB-INF/lib', include: ['*.jar'])
      compile fileTree(dir: '//opt/jenkins/wcs_artifacts/WCS_trunk', include: ['beanstyler.jar', 'UnycoIntegrationBean.jar', 'UnycoModels.jar'])
      compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
      compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
      testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "5.2.0"
      testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "1.2.0"
  }
  
  task createWCSAdminWar(type: War, dependsOn: [test, classes]) {
      baseName = 'WCSAdmin'
      destinationDir = file("$buildDir/dist")
  }
  
  task createUnycoAdminWar(type: War, dependsOn: [test, classes]) {
      baseName = 'UnycoAdmin'
      destinationDir = file("$buildDir/dist")
  }
  
  task createDists(dependsOn: [createWCSAdminWar, createUnycoAdminWar])
  
  defaultTasks 'build'
  </code></pre>
  
  <p>And this is the <strong>.classpath</strong> file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
      &lt;classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoIntegrationMessages"/&gt;
      &lt;classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoModels"/&gt;
      &lt;classpathentry kind="src" path="src/main/java"/&gt;
      &lt;classpathentry kind="src" path="src/test/java"/&gt;
      &lt;classpathentry kind="src" path="src/main/resources"/&gt;
      &lt;classpathentry kind="src" path="src/test/resources"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"&gt;
          &lt;attributes&gt;
              &lt;attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/&gt;
          &lt;/attributes&gt;
      &lt;/classpathentry&gt;
      &lt;classpathentry kind="output" path="bin"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p>Inside <strong>webapp/WEB-INF/lib/</strong> I have the <strong>junit-4.12.jar</strong> file</p>
  
  <p>Can anyone help me? Thanks</p>