JAL-3830 Look for --headless mode and add -Djava.awt.headless=true to java invocation...
[jalview.git] / src / jalview / bin / Launcher.java
index 246f0a2..f199002 100644 (file)
@@ -50,8 +50,7 @@ public class Launcher
 {
   private final static String startClass = "jalview.bin.Jalview";
 
-  private final static String dockIconPath = ChannelProperties
-          .getProperty("logo.512");
+  private final static String headlessProperty = "java.awt.headless";
 
   private static boolean checkJVMSymlink(String testBin)
   {
@@ -130,6 +129,7 @@ public class Launcher
     boolean debug = false;
     boolean wait = true;
     boolean quiet = false;
+    boolean headless = false;
     // must set --debug before --launcher...
     boolean launcherstop = false;
     boolean launcherprint = false;
@@ -145,6 +145,10 @@ public class Launcher
       {
         quiet = true;
       }
+      if (arg.equals("--headless"))
+      {
+        headless = true;
+      }
       if (debug && arg.equals("--launcherprint"))
       {
         launcherprint = true;
@@ -224,6 +228,7 @@ public class Launcher
     boolean memSet = false;
     boolean dockIcon = false;
     boolean dockName = false;
+    boolean headlessProp = false;
     for (int i = 0; i < command.size(); i++)
     {
       String arg = command.get(i);
@@ -244,6 +249,10 @@ public class Launcher
       {
         dockName = true;
       }
+      else if (arg.startsWith("-D" + headlessProperty + "="))
+      {
+        headlessProp = true;
+      }
     }
 
     if (!memSet)
@@ -262,6 +271,8 @@ public class Launcher
     {
       if (!dockIcon)
       {
+        String dockIconPath = System.getProperty("getdownappdir", ".")
+                + File.separator + "resource/jalview_logo.png";
         command.add("-Xdock:icon=" + dockIconPath);
       }
       if (!dockName)
@@ -277,6 +288,11 @@ public class Launcher
                 + appName);
       }
     }
+    if (headless && !headlessProp)
+    {
+      System.setProperty(headlessProperty, "true");
+      command.add("-D" + headlessProperty + "=true");
+    }
 
     String scalePropertyArg = HiDPISetting.getScalePropertyArg();
     if (scalePropertyArg != null)