title: Java execution not working with -classpath
body: <p>Test.java</p>
  
  <pre><code>package test;
  
   import shape.twod.*;
   import shape.threed.*;
   import shape.*;
  
  public class Test {
  
      /**
       * Creates a new instance of &lt;code&gt;Test&lt;/code&gt;.
       */
       int o;
      public Test() {
  
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          // TODO code application logic here
          ObjActions obj[] = new ObjActions[4];
          obj[0] = new Line(1,2,3,4);
          obj[1] = new Circle(1,2,3);
          obj[2] = new Line3D(1,2,3,4,5,6);
          obj[3] = new Sphere(1,2,3,4);
          for(ObjActions x: obj)
              x.draw();
          ObjActions.Actions2D o =(Circle)obj[1];
          //Actions2D o =(Circle)obj[1];
          System.out.println("Area of circle "+o.area());
          ObjActions.Actions3D op = (Sphere)obj[3];
          System.out.println("Volume of sphere "+op.volume());
      }
  }
  </code></pre>
  
  <p>Its location is <code>D:\Program\Javalearningprograms</code> and the location of packages used is <code>D:\Program\Javalearningprograms\PackageCheck</code></p>
  
  <p>First I compiled it with </p>
  
  <p><code>javac -classpath .\PackageCheck -d .\ Test.java</code> </p>
  
  <p>It compiled successfully and created Test.class in <code>.\test</code>, then I used this</p>
  
  <p><code>java -classpath .\PackageCheck test.Test</code></p>
  
  <p>and got <code>Error: Could not find or load main class test.Test</code></p>
  
  <p>so I tried with the full path:</p>
  
  <p><code>java -classpath D:\Program\Javalearningprograms\PackageCheck\ test.Test</code></p>
  
  <p>and</p>
  
  <p><code>java -classpath D:\Program\Javalearningprograms\PackageCheck test.Test</code></p>
  
  <p>still got <code>Error: Could not find or load main class test.Test</code></p>
  
  <p>So then to check weather the .class file has any errors I moved folder <code>.\test</code> to <code>D:\Program\Javalearningprograms\PackageCheck</code> and tried</p>
  
  <p><code>java test.Test</code> from <code>D:\Program\Javalearningprograms\PackageCheck</code> and the program ran successfully</p>
  
  <p>then I set <code>CLASSPATH</code> environment variable to <code>D:\Program\Javalearningprograms\PackageCheck</code> and cleaned the .class files and then tried </p>
  
  <p><code>javac -classpath .\PackageCheck -d .\ Test.java</code> it created Test.class in <code>.\test</code> folder and the I used </p>
  
  <p><code>java test.Test</code> and the program ran successfully, I tried  </p>
  
  <p><code>java -classpath .\PackageCheck test.Test</code></p>
  
  <p><code>java -classpath .\PackageCheck\ test.Test</code></p>
  
  <p><code>java -classpath D:\Program\Javalearningprograms\PackageCheck test.Test</code></p>
  
  <p><code>java -classpath D:\Program\Javalearningprograms\PackageCheck\ test.Test</code></p>
  
  <p>and got <code>Error: Could not find or load main class test.Test</code></p>
  
  <p>I dont know why <code>-classpath</code> is not working with <code>java</code> command, what am I doing wrongly?</p>
  
  <pre><code>    Directory: D:\Program\Javalearningprograms\PackageCheck
  
  
  Mode                LastWriteTime         Length Name
  ----                -------------         ------ ----
  d-----        09-Dec-15   1:35 PM                baseobj
  d-----        09-Dec-15   1:35 PM                shape
  -a----        09-Dec-15   1:33 PM            559 Circle.java
  -a----        09-Dec-15   1:33 PM            566 Line.java
  -a----        09-Dec-15   1:33 PM            627 Line3D.java
  -a----        09-Dec-15   1:32 PM            384 ObjActions.java
  -a----        08-Dec-15   9:58 PM            340 Point.java
  -a----        08-Dec-15   9:58 PM            302 Point3D.java
  -a----        08-Dec-15  10:05 PM            343 PointTest.java
  -a----        09-Dec-15   1:33 PM            547 Sphere.java
  </code></pre>