4 import java.io.IOException;
5 import java.lang.management.ManagementFactory;
6 import java.util.ArrayList;
10 private final static String startClass = "jalview.bin.Jalview";
12 private final static String dockIconPath = "JalviewLogo_Huge.png";
14 public static void main(String[] args)
16 final String javaBin = System.getProperty("java.home") + File.separator
17 + "bin" + File.separator + "java";
19 ArrayList<String> command = new ArrayList<>();
22 String memSetting = null;
24 boolean isAMac = System.getProperty("os.name").indexOf("Mac") > -1;
26 for (String jvmArg : ManagementFactory.getRuntimeMXBean()
32 command.add(ManagementFactory.getRuntimeMXBean().getClassPath());
33 ArrayList<String> arguments = new ArrayList<>();
34 for (String arg : args)
39 // add memory setting if not specified
40 boolean memSet = false;
41 boolean dockIcon = false;
42 boolean dockName = false;
43 ARG: for (int i = 0; i < command.size(); i++)
45 String arg = command.get(i);
46 if (arg.startsWith("-Xmx"))
51 else if (arg.startsWith("-Xdock:icon"))
55 else if (arg.startsWith("-Xdock:name"))
63 long maxMemLong = MemorySetting.getMemorySetting();
67 memSetting = "-Xmx" + Long.toString(maxMemLong);
68 command.add(memSetting);
76 command.add("-Xdock:icon=" + dockIconPath);
80 // -Xdock:name=... doesn't actually work :(
81 // Leaving it in in case it gets fixed
82 command.add("-Xdock:name=" + "Jalview");
86 command.add(startClass);
87 command.addAll(arguments);
89 final ProcessBuilder builder = new ProcessBuilder(command);
91 // System.out.println("COMMAND: " + String.join(" ", builder.command()));
92 System.out.println("Running " + startClass + " with "
93 + (memSetting == null ? "no memSetting" : memSetting));
95 if (System.getProperty("launcherstop") != null
96 && System.getProperty("launcherstop").equals("true"))
103 Process process = builder.start();
105 } catch (IOException e)
107 if (e.getMessage().toLowerCase().contains("memory"))
109 System.out.println("Caught a memory exception: " + e.getMessage());
110 // Probably the "Cannot allocate memory" error, try without the memory setting
111 ArrayList<String> commandNoMem = new ArrayList<>();
112 for (int i = 0; i < command.size(); i++)
114 if (!command.get(i).startsWith("-Xmx"))
116 commandNoMem.add(command.get(i));
119 final ProcessBuilder builderNoMem = new ProcessBuilder(
121 System.out.println("NO MEM COMMAND: "
122 + String.join(" ", builderNoMem.command()));
125 builderNoMem.inheritIO();
126 Process processNoMem = builderNoMem.start();
127 processNoMem.waitFor();
128 } catch (Exception ex)
130 ex.printStackTrace();
137 } catch (Exception e)