|| System.getProperty("java.version").startsWith("1.9.");
if (maxMemory < 1024 * 14)
{
- String cmd = "";
+ ArrayList<String> cmd = new ArrayList();
+
+ boolean dontspawn=false;
for (String r : args)
{
- cmd += (cmd.length() == 0) ? r : " " + r;
+ cmd.add(r);
+ if (r.indexOf("-Xmx")>-1) {
+ dontspawn=true;
+ break;
+ }
}
- if (cmd.indexOf("-Xmx") == -1)
+ if (!dontspawn)
{
- cmd = "-Xmx15G " + cmd;
- System.err.println("relaunching with 15G: " + cmd);
- Worker worker = Worker.jalviewDesktopRunner(false, cmd, 0,
- "-Xmx15G"
- + (is9or10 ? " --add-modules=\"java.se.ee\"" : ""));
+ cmd.add("-Xmx15G");
+ String[] javargs=new String[1];
+ if (is9or10) {
+ javargs = new String[2];
+ javargs[1] = "--add-modules=java.se.ee";
+ }
+ javargs[0]="-Xmx15G";
+
+ System.err.print("relaunching with 15G: ");
+ for (String r : cmd)
+ {
+ System.err.print(r + " ");
+ }
+ System.err.println("");
+ Worker worker = Worker.jalviewDesktopRunner(false,
+ cmd.toArray(new String[0]), 0, javargs);
worker.doEcho();
try
{
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;
// not expanded by the shell
String classpath = getClassPath();
String javahome = System.getProperty("java.home");
-
- String _cmd = javahome + File.pathSeparator + "java "
+ File java = new File(javahome + File.separator + "bin"
+ + File.separator + "java");
+ if (!java.exists())
+ {
+ System.err.println("Can't find " + java.getAbsolutePath());
+ java = new File(javahome + File.separator + "bin"
+ + File.separator + "java.exe");
+ if (!java.exists())
+ {
+ System.err.println("Can't find " + java.getAbsolutePath());
+ throw new Error(
+ "Can't locate java in JAVA_HOME/bin/java or JAVA_HOME/bin/java.exe");
+ }
+ }
+ String _cmd = "\"" + javahome + "\" "
+ (withAwt ? "-Djava.awt.headless=true" : "")
+ " -classpath " + classpath + " " + javaArgs
+ " jalview.bin.Jalview ";
return worker;
}
+ public static Worker jalviewDesktopRunner(boolean withAwt, String[] args,
+ int timeout, String[] javaArgs)
+ {
+ // Note: JAL-3065 - don't include quotes for lib/* because the arguments are
+ // not expanded by the shell
+ String classpath = getClassPath();
+ String javahome = System.getProperty("java.home");
+ File java = new File(
+ javahome + File.separator + "bin" + File.separator + "java");
+ if (!java.exists())
+ {
+ System.err.println("Can't find " + java.getAbsolutePath());
+ java = new File(javahome + File.separator + "bin" + File.separator
+ + "java.exe");
+ if (!java.exists())
+ {
+ System.err.println("Can't find " + java.getAbsolutePath());
+ throw new Error(
+ "Can't locate java in JAVA_HOME/bin/java or JAVA_HOME/bin/java.exe");
+ }
+ }
+ ArrayList<String> _cmd = new ArrayList();
+ _cmd.add(java.getAbsolutePath());
+ if (withAwt)
+ {
+ _cmd.add("-Djava.awt.headless=true");
+ }
+ _cmd.add("-classpath");
+ _cmd.add(classpath);
+ _cmd.addAll(Arrays.asList(javaArgs));
+ _cmd.add("jalview.bin.Jalview");
+ _cmd.addAll(Arrays.asList(args));
+ Process ls2_proc = null;
+ Worker worker = null;
+ try
+ {
+ ls2_proc = Runtime.getRuntime()
+ .exec(_cmd.toArray(new String[_cmd.size()]));
+ } catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
+ if (ls2_proc != null)
+ {
+ BufferedReader outputReader = new BufferedReader(
+ new InputStreamReader(ls2_proc.getInputStream()));
+ BufferedReader errorReader = new BufferedReader(
+ new InputStreamReader(ls2_proc.getErrorStream()));
+ worker = new Worker(ls2_proc);
+ worker.start();
+ try
+ {
+ worker.join(timeout);
+ } catch (InterruptedException e)
+ {
+ // e.printStackTrace();
+ }
+ worker.setOutputReader(outputReader);
+ worker.setErrorReader(errorReader);
+ }
+ return worker;
+ }
+
class Echo
{
public Echo(final PrintStream out, final BufferedReader source)