# Cannot find junit and main method

**URL:** <https://discuss.gradle.org/t/cannot-find-junit-and-main-method/4882>\
**Category:** Old Forum Archive\
**Created:** [November 7, 2013, 8:08pm UTC](https://discuss.gradle.org/t/cannot-find-junit-and-main-method/4882 "2013-11-07T20:08:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PG1](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@PG1](https://discuss.gradle.org/u/PG1)\
**Post date:** [November 7, 2013, 8:08pm UTC](https://discuss.gradle.org/t/cannot-find-junit-and-main-method/4882/1 "2013-11-07T20:08:00Z")

</div>

Hi, I am new to gradle projects. My task when run, can’t find the junit related classes nor the main method. I want to use the junit that is bundled as a jar in the lib folder. I have a project structure like this -

```gradle
test
    ------lib
            ------junit-4.4.jar(with other jar files)
    ------code.jar

```

Here is my code -

```gradle
apply plugin: 'java'
  repositories {
 flatDir{
    dirs 'D:/test/lib'
 }
}
  dependencies {
   compile group: 'junit', name: 'junit', version: '4.4'
   }
     task runTest(type:JavaExec){
   main = 'com.org.mainMethod'
 classpath = files([repositories.flatDir,'D:/test/code.jar','D:/test/lib'])
}

```

The task fails because it cannot find the junit related files. I am completely lost now -

```gradle
java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class:com.org.mainMethod
Program will exit.

```

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 7, 2013, 11:00pm UTC](https://discuss.gradle.org/t/cannot-find-junit-and-main-method/4882/2 "2013-11-07T23:00:00Z")

</div>

‘flatDir’ dependencies don’t need a ‘group’, although it may not be a problem to declare one. Try to omit the group or use the shorthand notation (‘compile “:junit:4.4”’). The ‘classpath’ configuration for the ‘runTest’ task is incorrect (you can’t put a repository or a directory on a Java class path). If these are JUnit tests, you should probably use the ‘test’ task provided by the ‘java’ plugin instead.

---

<div class="post-metadata">

**Author:** ![PG1](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@PG1](https://discuss.gradle.org/u/PG1)\
**Post date:** [November 8, 2013, 12:35am UTC](https://discuss.gradle.org/t/cannot-find-junit-and-main-method/4882/3 "2013-11-08T00:35:00Z")

</div>

Thanks for the reply Peter. The biggest issue was that the jar files under the d:/test/lib were not getting included. After adding a dependency to include all jar files, the problem got resolved.

Also fixed the classpath as suggested 🙂

```gradle
javaRun fileTree(dir: 'D:/test/lib', include: '*.jar')

```
