JAL-3820 Create and use 'Jalview app' symblinks to java executable. Fixes grouped...
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / util / LaunchUtil.java
index 31a69c3..0781a11 100644 (file)
@@ -233,12 +233,47 @@ public class LaunchUtil
     public static final boolean isLinux () { return _isLinux; }
 
     /**
+     * Check if a symlink (or file) points to a JVM
+     */
+    private static boolean checkJVMSymlink(String testBin)
+    {
+      File testBinFile = new File(testBin);
+      if (!testBinFile.exists())
+      {
+        return false;
+      }
+      File targetFile = null;
+      try
+      {
+        targetFile = testBinFile.getCanonicalFile();
+      } catch (IOException e)
+      {
+        return false;
+      }
+      if (targetFile != null && ("java".equals(targetFile.getName())
+            || "java.exe".equals(targetFile.getName())))
+      {
+        return true;
+      }
+      return false;
+    }
+
+    /**
      * Checks whether a Java Virtual Machine can be located in the supplied path.
      */
     protected static String checkJVMPath (String vmhome, boolean windebug)
     {
         String vmbase = vmhome + File.separator + "bin" + File.separator;
-        String vmpath = vmbase + "java";
+        String appName = System.getProperty("channel.app_name", "Jalview");
+        String vmpath = vmbase + appName;
+        if (checkJVMSymlink(vmpath)) {
+          return vmpath;
+        }
+        vmpath = vmbase + "Jalview";
+        if (checkJVMSymlink(vmpath)) {
+          return vmpath;
+        }
+        vmpath = vmbase + "java";
         if (new File(vmpath).exists()) {
             return vmpath;
         }