< prev index next >

src/java.base/share/classes/sun/launcher/LauncherHelper.java

Print this page

  85  * A utility package for the java(1), javaw(1) launchers.
  86  * The following are helper methods that the native launcher uses
  87  * to perform checks etc. using JNI, see src/share/bin/java.c
  88  */
  89 public final class LauncherHelper {
  90 
  91     // No instantiation
  92     private LauncherHelper() {}
  93 
  94     // used to identify JavaFX applications
  95     private static final String JAVAFX_APPLICATION_MARKER =
  96             "JavaFX-Application-Class";
  97     private static final String JAVAFX_APPLICATION_CLASS_NAME =
  98             "javafx.application.Application";
  99     private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX =
 100             "sun.launcher.LauncherHelper$FXHelper";
 101     private static final String LAUNCHER_AGENT_CLASS = "Launcher-Agent-Class";
 102     private static final String MAIN_CLASS = "Main-Class";
 103     private static final String ADD_EXPORTS = "Add-Exports";
 104     private static final String ADD_OPENS = "Add-Opens";

 105 
 106     private static StringBuilder outBuf = new StringBuilder();
 107 
 108     private static final String INDENT = "    ";
 109     private static final String VM_SETTINGS     = "VM settings:";
 110     private static final String PROP_SETTINGS   = "Property settings:";
 111     private static final String LOCALE_SETTINGS = "Locale settings:";
 112 
 113     // sync with java.c and jdk.internal.misc.VM
 114     private static final String diagprop = "sun.java.launcher.diag";
 115     static final boolean trace = VM.getSavedProperty(diagprop) != null;
 116 
 117     private static final String defaultBundleName =
 118             "sun.launcher.resources.launcher";
 119 
 120     private static class ResourceBundleHolder {
 121         private static final ResourceBundle RB =
 122                 ResourceBundle.getBundle(defaultBundleName);
 123     }
 124     private static PrintStream ostream;

 615                         String cn = "sun.instrument.InstrumentationImpl";
 616                         Class<?> clazz = Class.forName(cn, false, null);
 617                         Method loadAgent = clazz.getMethod("loadAgent", String.class);
 618                         loadAgent.invoke(null, jarname);
 619                     } catch (Throwable e) {
 620                         if (e instanceof InvocationTargetException) e = e.getCause();
 621                         abort(e, "java.launcher.jar.error4", jarname);
 622                     }
 623                 });
 624             }
 625 
 626             // Add-Exports and Add-Opens
 627             String exports = mainAttrs.getValue(ADD_EXPORTS);
 628             if (exports != null) {
 629                 addExportsOrOpens(exports, false);
 630             }
 631             String opens = mainAttrs.getValue(ADD_OPENS);
 632             if (opens != null) {
 633                 addExportsOrOpens(opens, true);
 634             }







 635 
 636             /*
 637              * Hand off to FXHelper if it detects a JavaFX application
 638              * This must be done after ensuring a Main-Class entry
 639              * exists to enforce compliance with the jar specification
 640              */
 641             if (mainAttrs.containsKey(
 642                     new Attributes.Name(JAVAFX_APPLICATION_MARKER))) {
 643                 FXHelper.setFXLaunchParameters(jarname, LM_JAR);
 644                 return FXHelper.class.getName();
 645             }
 646 
 647             return mainValue.trim();
 648         } catch (IOException ioe) {
 649             abort(ioe, "java.launcher.jar.error1", jarname);
 650         }
 651         return null;
 652     }
 653 
 654     /**

  85  * A utility package for the java(1), javaw(1) launchers.
  86  * The following are helper methods that the native launcher uses
  87  * to perform checks etc. using JNI, see src/share/bin/java.c
  88  */
  89 public final class LauncherHelper {
  90 
  91     // No instantiation
  92     private LauncherHelper() {}
  93 
  94     // used to identify JavaFX applications
  95     private static final String JAVAFX_APPLICATION_MARKER =
  96             "JavaFX-Application-Class";
  97     private static final String JAVAFX_APPLICATION_CLASS_NAME =
  98             "javafx.application.Application";
  99     private static final String JAVAFX_FXHELPER_CLASS_NAME_SUFFIX =
 100             "sun.launcher.LauncherHelper$FXHelper";
 101     private static final String LAUNCHER_AGENT_CLASS = "Launcher-Agent-Class";
 102     private static final String MAIN_CLASS = "Main-Class";
 103     private static final String ADD_EXPORTS = "Add-Exports";
 104     private static final String ADD_OPENS = "Add-Opens";
 105     private static final String ENABLE_NATIVE_ACCESS = "Enable-Native-Access";
 106 
 107     private static StringBuilder outBuf = new StringBuilder();
 108 
 109     private static final String INDENT = "    ";
 110     private static final String VM_SETTINGS     = "VM settings:";
 111     private static final String PROP_SETTINGS   = "Property settings:";
 112     private static final String LOCALE_SETTINGS = "Locale settings:";
 113 
 114     // sync with java.c and jdk.internal.misc.VM
 115     private static final String diagprop = "sun.java.launcher.diag";
 116     static final boolean trace = VM.getSavedProperty(diagprop) != null;
 117 
 118     private static final String defaultBundleName =
 119             "sun.launcher.resources.launcher";
 120 
 121     private static class ResourceBundleHolder {
 122         private static final ResourceBundle RB =
 123                 ResourceBundle.getBundle(defaultBundleName);
 124     }
 125     private static PrintStream ostream;

 616                         String cn = "sun.instrument.InstrumentationImpl";
 617                         Class<?> clazz = Class.forName(cn, false, null);
 618                         Method loadAgent = clazz.getMethod("loadAgent", String.class);
 619                         loadAgent.invoke(null, jarname);
 620                     } catch (Throwable e) {
 621                         if (e instanceof InvocationTargetException) e = e.getCause();
 622                         abort(e, "java.launcher.jar.error4", jarname);
 623                     }
 624                 });
 625             }
 626 
 627             // Add-Exports and Add-Opens
 628             String exports = mainAttrs.getValue(ADD_EXPORTS);
 629             if (exports != null) {
 630                 addExportsOrOpens(exports, false);
 631             }
 632             String opens = mainAttrs.getValue(ADD_OPENS);
 633             if (opens != null) {
 634                 addExportsOrOpens(opens, true);
 635             }
 636             String enableNativeAccess = mainAttrs.getValue(ENABLE_NATIVE_ACCESS);
 637             if (enableNativeAccess != null) {
 638                 if (!enableNativeAccess.equals("ALL-UNNAMED")) {
 639                     throw new IllegalArgumentException("Only ALL-UNNAMED allowed as value for " + ENABLE_NATIVE_ACCESS);
 640                 }
 641                 Modules.addEnableNativeAccessToAllUnnamed();
 642             }
 643 
 644             /*
 645              * Hand off to FXHelper if it detects a JavaFX application
 646              * This must be done after ensuring a Main-Class entry
 647              * exists to enforce compliance with the jar specification
 648              */
 649             if (mainAttrs.containsKey(
 650                     new Attributes.Name(JAVAFX_APPLICATION_MARKER))) {
 651                 FXHelper.setFXLaunchParameters(jarname, LM_JAR);
 652                 return FXHelper.class.getName();
 653             }
 654 
 655             return mainValue.trim();
 656         } catch (IOException ioe) {
 657             abort(ioe, "java.launcher.jar.error1", jarname);
 658         }
 659         return null;
 660     }
 661 
 662     /**
< prev index next >