// Creates a new thread, runs the program in that thread, and reports any errors as needed.
    private void run(String clazz) {
      try {
        // Makes sure the JVM resets if it's already running.
        if (JVMrunning) kill();

        // Some String constants for java path and OS-specific separators.
        String separator = System.getProperty("file.separator");
        String path = System.getProperty("java.home") + separator + "bin" + separator + "java";

        // Tries to run compiled code.
        ProcessBuilder builder = new ProcessBuilder(path, clazz);

        // Should be good now! Everything past this is on you. Don't mess it up.
        println(
            "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
        println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr);

        JVM = builder.start();

        // Note that as of right now, there is no support for input. Only output.
        Reader errorReader = new InputStreamReader(JVM.getErrorStream());
        Reader outReader = new InputStreamReader(JVM.getInputStream());
        // Writer inReader = new OutputStreamWriter(JVM.getOutputStream());

        redirectErr = redirectIOStream(errorReader, err);
        redirectOut = redirectIOStream(outReader, out);
        // redirectIn = redirectIOStream(null, inReader);
      } catch (Exception e) {
        // This catches any other errors we might get.
        println("Some error thrown", progErr);
        logError(e.toString());
        displayLog();
        return;
      }
    }
Esempio n. 2
0
  public void restartApplication() {

    try {

      final String javaBin =
          System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
      final File currentJar =
          new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI());

      System.out.println("javaBin " + javaBin);
      System.out.println("currentJar " + currentJar);
      System.out.println("currentJar.getPath() " + currentJar.getPath());

      /* is it a jar file? */
      // if(!currentJar.getName().endsWith(".jar")){return;}

      try {

        // xmining = 0;
        // systemx.shutdown();

      } catch (Exception e) {
        e.printStackTrace();
      }

      /* Build command: java -jar application.jar */
      final ArrayList<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add("-Xms256m");
      command.add("-Xmx1024m");
      command.add(currentJar.getPath());

      final ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();

      // try{Thread.sleep(10000);} catch (InterruptedException e){}

      // close and exit
      SystemTray.getSystemTray().remove(network.icon);
      System.exit(0);

    } // try
    catch (Exception e) {
      JOptionPane.showMessageDialog(null, e.getCause());
    }
  } // ******************************
Esempio n. 3
0
 private void startProcess(List<String> command) {
   ProcessBuilder processBuilder = new ProcessBuilder(command);
   DarkMod darkMod = DarkMod.getInstance();
   DarkModUI ui = darkMod.getUI();
   try {
     if (ui != null) {
       ui.setVisible(false);
       ui.dispose();
     }
     Process process = processBuilder.start();
     StreamRedirectFactory.createInputToOutputRedirect(process.getInputStream(), System.out);
     StreamRedirectFactory.createInputToOutputRedirect(process.getErrorStream(), System.err);
     StreamRedirectFactory.createInputToOutputRedirect(System.in, process.getOutputStream());
     System.exit(process.waitFor());
   } catch (Exception exception) {
     exception.printStackTrace();
     System.exit(-1);
   }
 }
Esempio n. 4
0
  private void restartApp() {
    if (!updateThis()) {
      JOptionPane.showMessageDialog(
          getProgressPanel().getParent(),
          "The update has completed successfully, but the control panel "
              + "was unable to restart itself automatically. Please close then "
              + "restart the control panel manually to use the updated version.",
          "Update Completed",
          JOptionPane.WARNING_MESSAGE);
      return;
    }
    String javaBin =
        System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
    try {
      String appPath = FileUtil.getJarFile().getPath();
      String newJarName = _differ.getNewJarName();
      if (!(newJarName == null || appPath.endsWith(newJarName))) {
        appPath = getPathForNewAppName(appPath);
        if (appPath == null) {
          throw new IllegalArgumentException();
        }
      }

      java.util.List<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add(FileUtil.getJarFile().getPath());
      command.add("-updateCompleted");

      ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();
      System.exit(0);
    } catch (Exception e) {
      showError("Failed to restart the Control Panel. Please restart manually.");
    }
  }