title: how to create a jar with compiled classes from a source jar in java
body: <p>I know how to create a jar from .java or .class files.</p>
  
  <p>I have a <code>sources.jar</code> that contains <code>.java</code> files. I want to compile these classes and pack into a <code>jar</code> again.</p>
  
  <p>for example:
  This is the jar I want to compile:</p>
  
  <p><code>hadoop-mapreduce-examples-2.2.0-test-sources.jar</code>.</p>
  
  <p>I did <code>jar xvf hadoop-mapreduce-examples-2.2.0-test-sources.jar</code> to extract everything.</p>
  
  <p>I now have</p>
  
  <pre><code>    ls
      META-INF    org
  
      ls org/apache/hadoop/
  examples    mapreduce
  
      ls org/apache/hadoop/examples/
  TestBaileyBorweinPlouffe.java   TestWordStats.java      pi              terasort
  </code></pre>
  
  <p>As you can notice, I have two packages within <code>org.apache.hadoop</code>, "examples and mapreduce", both of which have to be compiled. And I have sub-packages within "examples" that needs to be compiled.</p>
  
  <pre><code>javac org/apache/hadoop/mapreduce/lib/db/TestDBJob.java
  </code></pre>
  
  <p>This compiled fine</p>
  
  <p>But How can I compile recursively. I tried using wildcard '*'.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>javac -cp org/apache/hadoop/examples/*
  javac: invalid flag: org/apache/hadoop/examples/pi
  Usage: javac &lt;options&gt; &lt;source files&gt;
  use -help for a list of possible options
  javac org/apache/hadoop/examples/*.*
  </code></pre>
  
  <p>In the last <code>javac</code> executed above, I don't see the subpackages being compiled. only the top-level java files was compiled.</p>
  
  <p>Is there a simple solution such as </p>
  
  <p><code>javac -jar &lt;input.jar&gt; &lt;output.jar&gt;</code> will result in <code>&lt;output-jar&gt;</code> that has compiled files in it.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>To re-iterate my question:</p>
  
  <p>given a jar that has only <code>.java</code> files, I want a jar file that has <code>.class</code> files in the simplest possible way</p>