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)