title: How to run a Java program using ProcessBuilder inside the other Java program. (with -cp and -Xbootclasspath commands)
body: <p>Here is my code.</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) {
          String directory = System.getProperty("user.home") + File.separator + "cache";
          System.out.println(directory); // "/Users/byron1st/cache"
          try{
              ProcessBuilder builder = new ProcessBuilder("java",
                      "-cp", directory,
                      "-Xbootclasspath/p:", directory,
                      "framework.PFSystemMain");
              builder.redirectErrorStream(true);
              builder.redirectOutput(new File(System.getProperty("user.home") + "/output.txt"));
              builder.start();
          } catch(IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>This program builds a process to run a java program with -cp and -Xbootclasspath commands. Classes of the target program are in <code>/Users/byron1st/cache</code> folder.</p>
  
  <p><a href="https://i.stack.imgur.com/JCoUn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JCoUn.jpg" alt="enter image description here"></a></p>
  
  <p>What I want to do is to run <code>java -cp /Users/byron1st/cache -Xbootclasspath/p: /Users/byron1st/cache framework.PFSystemMain</code></p>
  
  <p>(The reason that I use <code>Xbootclasspath/p:</code> is that I have some instrumented classes to log.)</p>
  
  <p>This code cannot run the process and just produce an error message meaning "It cannot find or load a default class called '.Users.byron1st.cache'". (I'm sorry for showing the error message directly because it is written in Korean.)</p>
  
  <p>What is wrong with my code to use ProcessBuilder?</p>