title: Running Junit test from command line
body: <p>So I wrote a class called <code>Item</code> and using Junit wrote a test called <code>ItemTest</code> and I want to execute my test from a command line. This is steps that I followed:</p>
  
  <ol>
  <li><p>set the path, to run java.exe and set the classpath to libraries</p>
  
  <pre><code>...&gt; set path="C:\Program Files (x86)\Java\jdk1.7.0_40\bin"
  ...&gt; set classpath=C:\Program Files (x86)\Java\hamcrest-core-1.3.jar; C:\Program Files (x86)\Java\junit-4.11.jar
  </code></pre></li>
  <li><p>then i simply run org.junit.runner.JUnitCore to see if added libs were in classpath        </p>
  
  <pre><code>...&gt;java org.junit.runner.JUnitCore
  </code></pre>
  
  <p>the output was</p>
  
  <pre><code>JUnit version 4.11
  Time: 0,001
  OK (0 tests)
  </code></pre></li>
  <li><p>Then I compiled without an error <code>Item</code> and <code>ItemTest</code></p>
  
  <pre><code>C:\Users\User\IdeaProjects\My_project\src&gt;javac .\main\java\Item.java .\test\java\ItemTest.java
  </code></pre></li>
  <li><p>Then try ro run this classes</p>
  
  <pre><code>C:\Users\User\IdeaProjects\My_project\src&gt;java org.junit.runner.JUnitCore main.java.Item test.java.ItemTest
  </code></pre></li>
  <li><p>In the end I got this</p>
  
  <pre><code>JUnit version 4.11
  Exception in thread "main" java.lang.NoClassDefFoundError: main/java/Item (wrong name: Item)
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14 2)
  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:190)
  at org.junit.runner.JUnitCore.runMain(JUnitCore.java:86)
  at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
  at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
  </code></pre>
  
  <p>How to fix this ? Should I put <code>Item</code>in classpath ?</p></li>
  </ol>
  
  <p><strong>UPD#1</strong></p>
  
  <p>Put this path in my classpath doesn't work (with and without <code>src</code>):</p>
  
  <pre><code>    C:\Users\User\IdeaProjects\My_project\src&gt; 
  </code></pre>
  
  <p><strong>UPD#2</strong></p>
  
  <p>When I want to run the class I adress to him as he stores in file system or in what packages he lays ? Because I don't have packages and so <code>My_project</code> apart from being project name is a module name.</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>This is the way - I add to classpath next paths:</p>
  
  <ol>
  <li><p>The path to class <code>Item</code>:</p>
  
  <pre><code>C:\Users\User\IdeaProjects\My_project\src\main\java\;
  </code></pre></li>
  <li><p>The path to test class <code>ItemTest</code>:</p>
  
  <pre><code>C:\Users\User\IdeaProjects\My_project\src\test\java\;
  </code></pre></li>
  <li><p>Then simply run:</p>
  
  <pre><code>...&gt;java org.junit.runner.JUnitCore ItemTest
  </code></pre></li>
  </ol>