Changeset 5904 in josm for trunk/src/org
- Timestamp:
- 2013-04-26T00:35:45+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/RestartAction.java
r5857 r5904 10 10 import java.io.IOException; 11 11 import java.lang.management.ManagementFactory; 12 import java.util.ArrayList; 13 import java.util.Arrays; 14 import java.util.Collections; 12 15 import java.util.List; 13 16 … … 52 55 try { 53 56 // java binary 54 String java = System.getProperty("java.home") + "/bin/java";57 final List<String> cmd = new ArrayList<String>(Collections.singleton(System.getProperty("java.home") + "/bin/java")); 55 58 // vm arguments 56 List<String> vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); 57 StringBuffer vmArgsOneLine = new StringBuffer(); 58 for (String arg : vmArguments) { 59 for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { 59 60 // if it's the agent argument : we ignore it otherwise the 60 61 // address of the old application and the new one will be in conflict 61 62 if (!arg.contains("-agentlib")) { 62 vmArgsOneLine.append(arg); 63 vmArgsOneLine.append(" "); 63 cmd.add(arg); 64 64 } 65 65 } 66 // init the command to execute, add the vm args67 final StringBuffer cmd = new StringBuffer("\"" + java + "\" " + vmArgsOneLine);68 66 // program main and program arguments (be careful a sun property. might not be supported by all JVM) 69 67 String[] mainCommand = System.getProperty("sun.java.command").split(" "); … … 71 69 if (mainCommand[0].endsWith(".jar")) { 72 70 // if it's a jar, add -jar mainJar 73 cmd.append("-jar " + new File(mainCommand[0]).getPath()); 71 cmd.add("-jar"); 72 cmd.add(new File(mainCommand[0]).getPath()); 74 73 } else { 75 74 // else it's a .class, add the classpath and mainClass 76 cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]); 75 cmd.add("-cp"); 76 cmd.add("\"" + System.getProperty("java.class.path") + "\""); 77 cmd.add(mainCommand[0]); 77 78 } 78 79 // finally add program arguments 79 for (String arg : Main.commandLineArgs) { 80 cmd.append(" "); 81 cmd.append(arg); 82 } 80 cmd.addAll(Arrays.asList(Main.commandLineArgs)); 83 81 // execute the command in a shutdown hook, to be sure that all the 84 82 // resources have been disposed before restarting the application … … 87 85 public void run() { 88 86 try { 89 Runtime.getRuntime().exec(cmd.to String());87 Runtime.getRuntime().exec(cmd.toArray(new String[]{})); 90 88 } catch (IOException e) { 91 89 e.printStackTrace();
Note:
See TracChangeset
for help on using the changeset viewer.