title: use Java to run "tar" command, but it costs much time to generate the tar file
body: <p>In my project, i need generate an agent for users, and the agent include some jars(about 22M),some source class(about 200k) and a XML. The server will generate different xml for defferent user,so I have to generate the agent dynamically. I used <code>Runtime.getRuntime().exec("tar...")</code> to tar the files to generate agents. <br/><br/>When I run the unit test , the generation costs a lot of time, about 2min for every agent. I cann't let the user wait a page for 2min...so do it exists any other way to make this program more efficiency, or there is another way to generate the agent fast and smoothly?? appreciate!</p>
  
  <pre><code> /**
    * tar the agents
    * @param inputFiles agent files
    * @param outputFile agent tar
    * @param baseDir the directory path to run "tar" command
    */
   public static void tarFile(String[] inputFiles,String outputFile,String baseDir){
       String cmd="tar -zcf "+outputFile+" ";
       for (int i = 0; i &lt; inputFiles.length; i++) {
          cmd+=inputFiles[i]+" ";
      }
       System.out.println(cmd);
       try {
          Process process=Runtime.getRuntime().exec(cmd, null, new File(baseDir));
          BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream()));
          String s;
          while ((s=bufferedReader.readLine())!=null) {
              System.out.println(s);
          }
          process.waitFor();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
   }
  </code></pre>
  
  <p>this is my tar class, the param--basedir is to set the command's execution path</p>