title: How to create jar File while using another jar file?
body: <p>I'm trying to write an application  .In the app I use another jar file (opr.jar)  .In opr.jar(d:\opr.jar) I have an interface Operator  :</p>
  
  <pre><code>package operatorAPI;
  
  public interface Operator
  {
      int calculate(int num1 , int num2);
  }
  </code></pre>
  
  <p>Also I have class Plus(d:\math\Plus) that implement Operator Interface  :</p>
  
  <pre><code>package math;
  
  import operatorAPI.*;
  
  public class Plus implements Operator
  {
      public int calculate(int num1 , int num2)
      {
          return num1 + num2;
      }
  }
  </code></pre>
  
  <p>In the main program(d:\source\main\Sum) I load class Plus and use Operator interface  :</p>
  
  <pre><code>package source.main;
  
  import java.util.*;
  import java.io.*;
  import java.net.URL;
  import java.net.URLClassLoader;
  import operatorAPI.*;
  
  
  public class Sum
  {
      public static void main(String[] args) throws Exception
      {
          File operatorFile = new File("D:\\");
          URL operatorFilePath = operatorFile.toURL();
          URL[] operatorFilePaths = new URL[]{operatorFilePath};
          ClassLoader operatorsLoader = new URLClassLoader(operatorFilePaths);
          Class currentClass = operatorsLoader.loadClass("math.Plus");
  
          Operator instance = (Operator) currentClass.newInstance();
          int output = instance.calculate(10,20);
          System.out.println("The result is :" + output);
      }
  }
  </code></pre>
  
  <p>I use command line to compile and run the program  .My app work fine but when I try make my main program (source.main.Sum) as a executable jar file named app.jar and run it I get this exception  :</p>
  
  <pre><code>NoClassDefFoundError : operatorAPI/Operator
  </code></pre>
  
  <p>I makeand run jar 0file like so  :</p>
  
  <pre><code>jar -cvfe app.jar source.main.Sum source/main/Sum.class 
  java -cp opr.jar;. -jar app.jar
  </code></pre>
  
  <p>Can anyone tell me why this happend?</p>