|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.launcher; |
|
|
|
/* |
|
* |
|
* <p><b>This is NOT part of any API supported by Sun Microsystems. |
|
* If you write code that depends on this, you do so at your own |
|
* risk. This code and its internal interfaces are subject to change |
|
* or deletion without notice.</b> |
|
* |
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.io.PrintStream; |
|
import java.io.UnsupportedEncodingException; |
|
import java.lang.reflect.Method; |
|
import java.lang.reflect.Modifier; |
|
import java.math.BigDecimal; |
|
import java.math.RoundingMode; |
|
import java.nio.charset.Charset; |
|
import java.nio.file.DirectoryStream; |
|
import java.nio.file.Files; |
|
import java.nio.file.Path; |
|
import java.text.Normalizer; |
|
import java.util.ResourceBundle; |
|
import java.text.MessageFormat; |
|
import java.util.ArrayList; |
|
import java.util.Collections; |
|
import java.util.Iterator; |
|
import java.util.List; |
|
import java.util.Locale; |
|
import java.util.Locale.Category; |
|
import java.util.Properties; |
|
import java.util.Set; |
|
import java.util.TreeSet; |
|
import java.util.jar.Attributes; |
|
import java.util.jar.JarFile; |
|
import java.util.jar.Manifest; |
|
import jdk.internal.platform.Container; |
|
import jdk.internal.platform.Metrics; |
|
|
|
public enum LauncherHelper { |
|
INSTANCE; |
|
private static final String MAIN_CLASS = "Main-Class"; |
|
|
|
private static StringBuilder outBuf = new StringBuilder(); |
|
|
|
private static final String INDENT = " "; |
|
private static final String VM_SETTINGS = "VM settings:"; |
|
private static final String PROP_SETTINGS = "Property settings:"; |
|
private static final String LOCALE_SETTINGS = "Locale settings:"; |
|
|
|
|
|
private static final String diagprop = "sun.java.launcher.diag"; |
|
final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null; |
|
|
|
private static final String defaultBundleName = |
|
"sun.launcher.resources.launcher"; |
|
private static class ResourceBundleHolder { |
|
private static final ResourceBundle RB = |
|
ResourceBundle.getBundle(defaultBundleName); |
|
} |
|
private static PrintStream ostream; |
|
private static final ClassLoader scloader = ClassLoader.getSystemClassLoader(); |
|
private static Class<?> appClass; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@SuppressWarnings("fallthrough") |
|
static void showSettings(boolean printToStderr, String optionFlag, |
|
long initialHeapSize, long maxHeapSize, long stackSize, |
|
boolean isServer) { |
|
|
|
initOutput(printToStderr); |
|
String opts[] = optionFlag.split(":"); |
|
String optStr = (opts.length > 1 && opts[1] != null) |
|
? opts[1].trim() |
|
: "all"; |
|
switch (optStr) { |
|
case "vm": |
|
printVmSettings(initialHeapSize, maxHeapSize, |
|
stackSize, isServer); |
|
break; |
|
case "properties": |
|
printProperties(); |
|
break; |
|
case "locale": |
|
printLocale(); |
|
break; |
|
case "system": |
|
if (System.getProperty("os.name").contains("Linux")) { |
|
printSystemMetrics(); |
|
break; |
|
} |
|
default: |
|
printVmSettings(initialHeapSize, maxHeapSize, stackSize, |
|
isServer); |
|
printProperties(); |
|
printLocale(); |
|
if (System.getProperty("os.name").contains("Linux")) { |
|
printSystemMetrics(); |
|
} |
|
break; |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
private static void printVmSettings( |
|
long initialHeapSize, long maxHeapSize, |
|
long stackSize, boolean isServer) { |
|
|
|
ostream.println(VM_SETTINGS); |
|
if (stackSize != 0L) { |
|
ostream.println(INDENT + "Stack Size: " + |
|
SizePrefix.scaleValue(stackSize)); |
|
} |
|
if (initialHeapSize != 0L) { |
|
ostream.println(INDENT + "Min. Heap Size: " + |
|
SizePrefix.scaleValue(initialHeapSize)); |
|
} |
|
if (maxHeapSize != 0L) { |
|
ostream.println(INDENT + "Max. Heap Size: " + |
|
SizePrefix.scaleValue(maxHeapSize)); |
|
} else { |
|
ostream.println(INDENT + "Max. Heap Size (Estimated): " |
|
+ SizePrefix.scaleValue(Runtime.getRuntime().maxMemory())); |
|
} |
|
ostream.println(INDENT + "Ergonomics Machine Class: " |
|
+ ((isServer) ? "server" : "client")); |
|
ostream.println(INDENT + "Using VM: " |
|
+ System.getProperty("java.vm.name")); |
|
ostream.println(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
private static void printProperties() { |
|
Properties p = System.getProperties(); |
|
ostream.println(PROP_SETTINGS); |
|
List<String> sortedPropertyKeys = new ArrayList<>(); |
|
sortedPropertyKeys.addAll(p.stringPropertyNames()); |
|
Collections.sort(sortedPropertyKeys); |
|
for (String x : sortedPropertyKeys) { |
|
printPropertyValue(x, p.getProperty(x)); |
|
} |
|
ostream.println(); |
|
} |
|
|
|
private static boolean isPath(String key) { |
|
return key.endsWith(".dirs") || key.endsWith(".path"); |
|
} |
|
|
|
private static void printPropertyValue(String key, String value) { |
|
ostream.print(INDENT + key + " = "); |
|
if (key.equals("line.separator")) { |
|
for (byte b : value.getBytes()) { |
|
switch (b) { |
|
case 0xd: |
|
ostream.print("\\r "); |
|
break; |
|
case 0xa: |
|
ostream.print("\\n "); |
|
break; |
|
default: |
|
// print any bizzare line separators in hex, but really |
|
|
|
ostream.printf("0x%02X", b & 0xff); |
|
break; |
|
} |
|
} |
|
ostream.println(); |
|
return; |
|
} |
|
if (!isPath(key)) { |
|
ostream.println(value); |
|
return; |
|
} |
|
String[] values = value.split(System.getProperty("path.separator")); |
|
boolean first = true; |
|
for (String s : values) { |
|
if (first) { |
|
ostream.println(s); |
|
first = false; |
|
} else { |
|
ostream.println(INDENT + INDENT + s); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
private static void printLocale() { |
|
Locale locale = Locale.getDefault(); |
|
ostream.println(LOCALE_SETTINGS); |
|
ostream.println(INDENT + "default locale = " + |
|
locale.getDisplayLanguage()); |
|
ostream.println(INDENT + "default display locale = " + |
|
Locale.getDefault(Category.DISPLAY).getDisplayName()); |
|
ostream.println(INDENT + "default format locale = " + |
|
Locale.getDefault(Category.FORMAT).getDisplayName()); |
|
printLocales(); |
|
ostream.println(); |
|
} |
|
|
|
private static void printLocales() { |
|
Locale[] tlocales = Locale.getAvailableLocales(); |
|
final int len = tlocales == null ? 0 : tlocales.length; |
|
if (len < 1 ) { |
|
return; |
|
} |
|
// Locale does not implement Comparable so we convert it to String |
|
|
|
Set<String> sortedSet = new TreeSet<>(); |
|
for (Locale l : tlocales) { |
|
sortedSet.add(l.toString()); |
|
} |
|
|
|
ostream.print(INDENT + "available locales = "); |
|
Iterator<String> iter = sortedSet.iterator(); |
|
final int last = len - 1; |
|
for (int i = 0 ; iter.hasNext() ; i++) { |
|
String s = iter.next(); |
|
ostream.print(s); |
|
if (i != last) { |
|
ostream.print(", "); |
|
} |
|
|
|
if ((i + 1) % 8 == 0) { |
|
ostream.println(); |
|
ostream.print(INDENT + INDENT); |
|
} |
|
} |
|
} |
|
|
|
public static void printSystemMetrics() { |
|
Metrics c = Container.metrics(); |
|
|
|
ostream.println("Operating System Metrics:"); |
|
|
|
if (c == null) { |
|
ostream.println(INDENT + "No metrics available for this platform"); |
|
return; |
|
} |
|
|
|
ostream.println(INDENT + "Provider: " + c.getProvider()); |
|
ostream.println(INDENT + "Effective CPU Count: " + c.getEffectiveCpuCount()); |
|
ostream.println(INDENT + "CPU Period: " + c.getCpuPeriod() + |
|
(c.getCpuPeriod() == -1 ? "" : "us")); |
|
ostream.println(INDENT + "CPU Quota: " + c.getCpuQuota() + |
|
(c.getCpuQuota() == -1 ? "" : "us")); |
|
ostream.println(INDENT + "CPU Shares: " + c.getCpuShares()); |
|
|
|
int cpus[] = c.getCpuSetCpus(); |
|
ostream.println(INDENT + "List of Processors, " |
|
+ cpus.length + " total: "); |
|
|
|
ostream.print(INDENT); |
|
for (int i = 0; i < cpus.length; i++) { |
|
ostream.print(cpus[i] + " "); |
|
} |
|
if (cpus.length > 0) { |
|
ostream.println(""); |
|
} |
|
|
|
cpus = c.getEffectiveCpuSetCpus(); |
|
ostream.println(INDENT + "List of Effective Processors, " |
|
+ cpus.length + " total: "); |
|
|
|
ostream.print(INDENT); |
|
for (int i = 0; i < cpus.length; i++) { |
|
ostream.print(cpus[i] + " "); |
|
} |
|
if (cpus.length > 0) { |
|
ostream.println(""); |
|
} |
|
|
|
int mems[] = c.getCpuSetMems(); |
|
ostream.println(INDENT + "List of Memory Nodes, " |
|
+ mems.length + " total: "); |
|
|
|
ostream.print(INDENT); |
|
for (int i = 0; i < mems.length; i++) { |
|
ostream.print(mems[i] + " "); |
|
} |
|
if (mems.length > 0) { |
|
ostream.println(""); |
|
} |
|
|
|
mems = c.getEffectiveCpuSetMems(); |
|
ostream.println(INDENT + "List of Available Memory Nodes, " |
|
+ mems.length + " total: "); |
|
|
|
ostream.print(INDENT); |
|
for (int i = 0; i < mems.length; i++) { |
|
ostream.print(mems[i] + " "); |
|
} |
|
if (mems.length > 0) { |
|
ostream.println(""); |
|
} |
|
|
|
ostream.println(INDENT + "CPUSet Memory Pressure Enabled: " |
|
+ c.isCpuSetMemoryPressureEnabled()); |
|
|
|
long limit = c.getMemoryLimit(); |
|
ostream.println(INDENT + "Memory Limit: " + |
|
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
|
|
limit = c.getMemorySoftLimit(); |
|
ostream.println(INDENT + "Memory Soft Limit: " + |
|
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
|
|
limit = c.getMemoryAndSwapLimit(); |
|
ostream.println(INDENT + "Memory & Swap Limit: " + |
|
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
|
|
limit = c.getKernelMemoryLimit(); |
|
ostream.println(INDENT + "Kernel Memory Limit: " + |
|
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
|
|
limit = c.getTcpMemoryLimit(); |
|
ostream.println(INDENT + "TCP Memory Limit: " + |
|
((limit >= 0) ? SizePrefix.scaleValue(limit) : "Unlimited")); |
|
|
|
ostream.println(INDENT + "Out Of Memory Killer Enabled: " |
|
+ c.isMemoryOOMKillEnabled()); |
|
|
|
ostream.println(""); |
|
} |
|
|
|
private enum SizePrefix { |
|
|
|
KILO(1024, "K"), |
|
MEGA(1024 * 1024, "M"), |
|
GIGA(1024 * 1024 * 1024, "G"), |
|
TERA(1024L * 1024L * 1024L * 1024L, "T"); |
|
long size; |
|
String abbrev; |
|
|
|
SizePrefix(long size, String abbrev) { |
|
this.size = size; |
|
this.abbrev = abbrev; |
|
} |
|
|
|
private static String scale(long v, SizePrefix prefix) { |
|
return BigDecimal.valueOf(v).divide(BigDecimal.valueOf(prefix.size), |
|
2, RoundingMode.HALF_EVEN).toPlainString() + prefix.abbrev; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
static String scaleValue(long v) { |
|
if (v < MEGA.size) { |
|
return scale(v, KILO); |
|
} else if (v < GIGA.size) { |
|
return scale(v, MEGA); |
|
} else if (v < TERA.size) { |
|
return scale(v, GIGA); |
|
} else { |
|
return scale(v, TERA); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static String getLocalizedMessage(String key, Object... args) { |
|
String msg = ResourceBundleHolder.RB.getString(key); |
|
return (args != null) ? MessageFormat.format(msg, args) : msg; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static void initHelpMessage(String progname) { |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.header", |
|
(progname == null) ? "java" : progname )); |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel", |
|
32)); |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.datamodel", |
|
64)); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
static void appendVmSelectMessage(String vm1, String vm2) { |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.vmselect", |
|
vm1, vm2)); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
static void appendVmSynonymMessage(String vm1, String vm2) { |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.hotspot", |
|
vm1, vm2)); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
static void appendVmErgoMessage(boolean isServerClass, String vm) { |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.ergo.message1", |
|
vm)); |
|
outBuf = (isServerClass) |
|
? outBuf.append(",\n" + |
|
getLocalizedMessage("java.launcher.ergo.message2") + "\n\n") |
|
: outBuf.append(".\n\n"); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static void printHelpMessage(boolean printToStderr) { |
|
initOutput(printToStderr); |
|
outBuf = outBuf.append(getLocalizedMessage("java.launcher.opt.footer", |
|
File.pathSeparator)); |
|
ostream.println(outBuf.toString()); |
|
} |
|
|
|
|
|
|
|
*/ |
|
static void printXUsageMessage(boolean printToStderr) { |
|
initOutput(printToStderr); |
|
ostream.println(getLocalizedMessage("java.launcher.X.usage", |
|
File.pathSeparator)); |
|
if (System.getProperty("os.name").contains("OS X")) { |
|
ostream.println(getLocalizedMessage("java.launcher.X.macosx.usage", |
|
File.pathSeparator)); |
|
} |
|
} |
|
|
|
static void initOutput(boolean printToStderr) { |
|
ostream = (printToStderr) ? System.err : System.out; |
|
} |
|
|
|
static String getMainClassFromJar(String jarname) { |
|
String mainValue = null; |
|
try (JarFile jarFile = new JarFile(jarname)) { |
|
Manifest manifest = jarFile.getManifest(); |
|
if (manifest == null) { |
|
abort(null, "java.launcher.jar.error2", jarname); |
|
} |
|
Attributes mainAttrs = manifest.getMainAttributes(); |
|
if (mainAttrs == null) { |
|
abort(null, "java.launcher.jar.error3", jarname); |
|
} |
|
mainValue = mainAttrs.getValue(MAIN_CLASS); |
|
if (mainValue == null) { |
|
abort(null, "java.launcher.jar.error3", jarname); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
if (mainAttrs.containsKey( |
|
new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { |
|
return FXHelper.class.getName(); |
|
} |
|
|
|
return mainValue.trim(); |
|
} catch (IOException ioe) { |
|
abort(ioe, "java.launcher.jar.error1", jarname); |
|
} |
|
return null; |
|
} |
|
|
|
// From src/share/bin/java.c: |
|
// enum LaunchMode { LM_UNKNOWN = 0, LM_CLASS, LM_JAR }; |
|
|
|
private static final int LM_UNKNOWN = 0; |
|
private static final int LM_CLASS = 1; |
|
private static final int LM_JAR = 2; |
|
|
|
static void abort(Throwable t, String msgKey, Object... args) { |
|
if (msgKey != null) { |
|
ostream.println(getLocalizedMessage(msgKey, args)); |
|
} |
|
if (trace) { |
|
if (t != null) { |
|
t.printStackTrace(); |
|
} else { |
|
Thread.dumpStack(); |
|
} |
|
} |
|
System.exit(1); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static Class<?> checkAndLoadMain(boolean printToStderr, |
|
int mode, |
|
String what) { |
|
initOutput(printToStderr); |
|
|
|
String cn = null; |
|
switch (mode) { |
|
case LM_CLASS: |
|
cn = what; |
|
break; |
|
case LM_JAR: |
|
cn = getMainClassFromJar(what); |
|
break; |
|
default: |
|
|
|
throw new InternalError("" + mode + ": Unknown launch mode"); |
|
} |
|
cn = cn.replace('/', '.'); |
|
Class<?> mainClass = null; |
|
try { |
|
mainClass = scloader.loadClass(cn); |
|
} catch (NoClassDefFoundError | ClassNotFoundException cnfe) { |
|
if (System.getProperty("os.name", "").contains("OS X") |
|
&& Normalizer.isNormalized(cn, Normalizer.Form.NFD)) { |
|
try { |
|
// On Mac OS X since all names with diacretic symbols are given as decomposed it |
|
// is possible that main class name comes incorrectly from the command line |
|
|
|
mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC)); |
|
} catch (NoClassDefFoundError | ClassNotFoundException cnfe1) { |
|
abort(cnfe, "java.launcher.cls.error1", cn); |
|
} |
|
} else { |
|
abort(cnfe, "java.launcher.cls.error1", cn); |
|
} |
|
} |
|
|
|
appClass = mainClass; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
if (mainClass.equals(FXHelper.class) || |
|
FXHelper.doesExtendFXApplication(mainClass)) { |
|
|
|
FXHelper.setFXLaunchParameters(what, mode); |
|
return FXHelper.class; |
|
} |
|
|
|
validateMainClass(mainClass); |
|
return mainClass; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static Class<?> getApplicationClass() { |
|
return appClass; |
|
} |
|
|
|
|
|
static void validateMainClass(Class<?> mainClass) { |
|
Method mainMethod; |
|
try { |
|
mainMethod = mainClass.getMethod("main", String[].class); |
|
} catch (NoSuchMethodException nsme) { |
|
|
|
abort(null, "java.launcher.cls.error4", mainClass.getName(), |
|
FXHelper.JAVAFX_APPLICATION_CLASS_NAME); |
|
return; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
int mod = mainMethod.getModifiers(); |
|
if (!Modifier.isStatic(mod)) { |
|
abort(null, "java.launcher.cls.error2", "static", |
|
mainMethod.getDeclaringClass().getName()); |
|
} |
|
if (mainMethod.getReturnType() != java.lang.Void.TYPE) { |
|
abort(null, "java.launcher.cls.error3", |
|
mainMethod.getDeclaringClass().getName()); |
|
} |
|
} |
|
|
|
private static final String encprop = "sun.jnu.encoding"; |
|
private static String encoding = null; |
|
private static boolean isCharsetSupported = false; |
|
|
|
|
|
|
|
|
|
*/ |
|
static String makePlatformString(boolean printToStderr, byte[] inArray) { |
|
initOutput(printToStderr); |
|
if (encoding == null) { |
|
encoding = System.getProperty(encprop); |
|
isCharsetSupported = Charset.isSupported(encoding); |
|
} |
|
try { |
|
String out = isCharsetSupported |
|
? new String(inArray, encoding) |
|
: new String(inArray); |
|
return out; |
|
} catch (UnsupportedEncodingException uee) { |
|
abort(uee, null); |
|
} |
|
return null; |
|
} |
|
|
|
static String[] expandArgs(String[] argArray) { |
|
List<StdArg> aList = new ArrayList<>(); |
|
for (String x : argArray) { |
|
aList.add(new StdArg(x)); |
|
} |
|
return expandArgs(aList); |
|
} |
|
|
|
static String[] expandArgs(List<StdArg> argList) { |
|
ArrayList<String> out = new ArrayList<>(); |
|
if (trace) { |
|
System.err.println("Incoming arguments:"); |
|
} |
|
for (StdArg a : argList) { |
|
if (trace) { |
|
System.err.println(a); |
|
} |
|
if (a.needsExpansion) { |
|
File x = new File(a.arg); |
|
File parent = x.getParentFile(); |
|
String glob = x.getName(); |
|
if (parent == null) { |
|
parent = new File("."); |
|
} |
|
try (DirectoryStream<Path> dstream = |
|
Files.newDirectoryStream(parent.toPath(), glob)) { |
|
int entries = 0; |
|
for (Path p : dstream) { |
|
out.add(p.normalize().toString()); |
|
entries++; |
|
} |
|
if (entries == 0) { |
|
out.add(a.arg); |
|
} |
|
} catch (Exception e) { |
|
out.add(a.arg); |
|
if (trace) { |
|
System.err.println("Warning: passing argument as-is " + a); |
|
System.err.print(e); |
|
} |
|
} |
|
} else { |
|
out.add(a.arg); |
|
} |
|
} |
|
String[] oarray = new String[out.size()]; |
|
out.toArray(oarray); |
|
|
|
if (trace) { |
|
System.err.println("Expanded arguments:"); |
|
for (String x : oarray) { |
|
System.err.println(x); |
|
} |
|
} |
|
return oarray; |
|
} |
|
|
|
|
|
private static class StdArg { |
|
final String arg; |
|
final boolean needsExpansion; |
|
StdArg(String arg, boolean expand) { |
|
this.arg = arg; |
|
this.needsExpansion = expand; |
|
} |
|
// protocol: first char indicates whether expansion is required |
|
// 'T' = true ; needs expansion |
|
|
|
StdArg(String in) { |
|
this.arg = in.substring(1); |
|
needsExpansion = in.charAt(0) == 'T'; |
|
} |
|
public String toString() { |
|
return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; |
|
} |
|
} |
|
|
|
static final class FXHelper { |
|
|
|
private static final String JAVAFX_APPLICATION_MARKER = |
|
"JavaFX-Application-Class"; |
|
private static final String JAVAFX_APPLICATION_CLASS_NAME = |
|
"javafx.application.Application"; |
|
private static final String JAVAFX_LAUNCHER_CLASS_NAME = |
|
"com.sun.javafx.application.LauncherImpl"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static final String JAVAFX_LAUNCH_MODE_CLASS = "LM_CLASS"; |
|
private static final String JAVAFX_LAUNCH_MODE_JAR = "LM_JAR"; |
|
|
|
|
|
|
|
|
|
*/ |
|
private static String fxLaunchName = null; |
|
private static String fxLaunchMode = null; |
|
|
|
private static Class<?> fxLauncherClass = null; |
|
private static Method fxLauncherMethod = null; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static void setFXLaunchParameters(String what, int mode) { |
|
|
|
try { |
|
fxLauncherClass = scloader.loadClass(JAVAFX_LAUNCHER_CLASS_NAME); |
|
|
|
|
|
|
|
|
|
*/ |
|
fxLauncherMethod = fxLauncherClass.getMethod("launchApplication", |
|
String.class, String.class, String[].class); |
|
|
|
|
|
int mod = fxLauncherMethod.getModifiers(); |
|
if (!Modifier.isStatic(mod)) { |
|
abort(null, "java.launcher.javafx.error1"); |
|
} |
|
if (fxLauncherMethod.getReturnType() != java.lang.Void.TYPE) { |
|
abort(null, "java.launcher.javafx.error1"); |
|
} |
|
} catch (ClassNotFoundException | NoSuchMethodException ex) { |
|
abort(ex, "java.launcher.cls.error5", ex); |
|
} |
|
|
|
fxLaunchName = what; |
|
switch (mode) { |
|
case LM_CLASS: |
|
fxLaunchMode = JAVAFX_LAUNCH_MODE_CLASS; |
|
break; |
|
case LM_JAR: |
|
fxLaunchMode = JAVAFX_LAUNCH_MODE_JAR; |
|
break; |
|
default: |
|
|
|
throw new InternalError(mode + ": Unknown launch mode"); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static boolean doesExtendFXApplication(Class<?> mainClass) { |
|
for (Class<?> sc = mainClass.getSuperclass(); sc != null; |
|
sc = sc.getSuperclass()) { |
|
if (sc.getName().equals(JAVAFX_APPLICATION_CLASS_NAME)) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static void main(String... args) throws Exception { |
|
if (fxLauncherMethod == null |
|
|| fxLaunchMode == null |
|
|| fxLaunchName == null) { |
|
throw new RuntimeException("Invalid JavaFX launch parameters"); |
|
} |
|
|
|
fxLauncherMethod.invoke(null, |
|
new Object[] {fxLaunchName, fxLaunchMode, args}); |
|
} |
|
} |
|
} |