37 import java.lang.reflect.InvocationTargetException;
38 import java.lang.reflect.Method;
39 import java.net.MalformedURLException;
40 import java.net.URL;
41 import java.net.URLClassLoader;
42 import java.security.AccessController;
43 import java.security.PrivilegedAction;
44 import java.util.ArrayList;
45 import java.util.LinkedList;
46 import java.util.List;
47 import java.util.concurrent.CountDownLatch;
48 import java.util.concurrent.atomic.AtomicBoolean;
49 import java.util.concurrent.atomic.AtomicReference;
50 import java.util.jar.Attributes;
51 import java.util.jar.JarFile;
52 import java.util.jar.Manifest;
53 import java.util.Base64;
54 import com.sun.javafx.jmx.MXExtension;
55 import com.sun.javafx.runtime.SystemProperties;
56
57
58 public class LauncherImpl {
59 /**
60 * When passed as launchMode to launchApplication, tells the method that
61 * launchName is the name of the JavaFX application class to launch.
62 */
63 public static final String LAUNCH_MODE_CLASS = "LM_CLASS";
64
65 /**
66 * When passed as launchMode to launchApplication, tells the method that
67 * launchName is a path to a JavaFX application jar file to be launched.
68 */
69 public static final String LAUNCH_MODE_JAR = "LM_JAR";
70
71 // set to true to debug launch issues from Java launcher
72 private static final boolean trace = false;
73
74 // set system property javafx.verbose to true to make the launcher noisy
75 private static final boolean verbose;
76
77 private static final String MF_MAIN_CLASS = "Main-Class";
78 private static final String MF_JAVAFX_MAIN = "JavaFX-Application-Class";
377 // Save the preloader class in a static field for later use when
378 // main calls back into launchApplication.
379 savedPreloaderClass = preClass;
380
381 // If there is a public static void main(String[]) method then call it
382 // otherwise just hand off to the other launchApplication method
383
384 Exception theEx = null;
385 try {
386 Method mainMethod = tempAppClass.getMethod("main",
387 new Class[] { (new String[0]).getClass() });
388 if (verbose) {
389 System.err.println("Calling main(String[]) method");
390 }
391 savedMainCcl = Thread.currentThread().getContextClassLoader();
392 mainMethod.invoke(null, new Object[] { args });
393 return;
394 } catch (NoSuchMethodException | IllegalAccessException ex) {
395 theEx = ex;
396 savedPreloaderClass = null;
397 } catch (InvocationTargetException ex) {
398 ex.printStackTrace();
399 abort(null, "Exception running application %1$s", tempAppClass.getName());
400 return;
401 }
402
403 // Verify appClass extends Application
404 if (!Application.class.isAssignableFrom(tempAppClass)) {
405 abort(theEx, "JavaFX application class %1$s does not extend javafx.application.Application", tempAppClass.getName());
406 }
407 appClass = tempAppClass.asSubclass(Application.class);
408
409 if (verbose) {
410 System.err.println("Launching application directly");
411 }
412 launchApplication(appClass, preClass, args);
413 }
414
415 private static URL fileToURL(File file) throws IOException {
416 return file.getCanonicalFile().toURI().toURL();
509 if (System.getProperty("http.proxyHost") != null
510 || System.getProperty("https.proxyHost") != null
511 || System.getProperty("ftp.proxyHost") != null
512 || System.getProperty("socksProxyHost") != null) {
513 if (verbose) {
514 System.out.println("Explicit proxy settings detected. Skip autoconfig.");
515 System.out.println(" http.proxyHost=" + System.getProperty("http.proxyHost"));
516 System.out.println(" https.proxyHost=" + System.getProperty("https.proxyHost"));
517 System.out.println(" ftp.proxyHost=" + System.getProperty("ftp.proxyHost"));
518 System.out.println(" socksProxyHost=" + System.getProperty("socksProxyHost"));
519 }
520 return;
521 }
522 if (System.getProperty("javafx.autoproxy.disable") != null) {
523 if (verbose) {
524 System.out.println("Disable autoproxy on request.");
525 }
526 return;
527 }
528
529 // grab deploy.jar
530 // Note that we don't need to keep deploy.jar in the JavaFX classloader
531 // it is only needed long enough to configure the proxy
532 String javaHome = System.getProperty("java.home");
533 File jreLibDir = new File(javaHome, "lib");
534 File deployJar = new File(jreLibDir, "deploy.jar");
535
536 URL[] deployURLs;
537 try {
538 deployURLs = new URL[] {
539 deployJar.toURI().toURL()
540 };
541 } catch (MalformedURLException ex) {
542 if (trace) {
543 System.err.println("Unable to build URL to deploy.jar: "+ex);
544 ex.printStackTrace();
545 }
546 return; // give up setting proxy, usually silently
547 }
548
549 try {
550 URLClassLoader dcl = new URLClassLoader(deployURLs);
551 Class sm = Class.forName("com.sun.deploy.services.ServiceManager",
552 true,
553 dcl);
554 Class params[] = {Integer.TYPE};
555 Method setservice = sm.getDeclaredMethod("setService", params);
556 String osname = System.getProperty("os.name");
557
558 String servicename;
559 if (osname.startsWith("Win")) {
560 servicename = "STANDALONE_TIGER_WIN32";
561 } else if (osname.contains("Mac")) {
562 servicename = "STANDALONE_TIGER_MACOSX";
563 } else {
564 servicename = "STANDALONE_TIGER_UNIX";
565 }
566 Object values[] = new Object[1];
567 Class pt = Class.forName("com.sun.deploy.services.PlatformType",
568 true,
569 dcl);
570 values[0] = pt.getField(servicename).get(null);
571 setservice.invoke(null, values);
572
573 Class dps = Class.forName(
574 "com.sun.deploy.net.proxy.DeployProxySelector",
575 true,
576 dcl);
577 Method m = dps.getDeclaredMethod("reset", new Class[0]);
578 m.invoke(null, new Object[0]);
579
580 if (verbose) {
581 System.out.println("Autoconfig of proxy is completed.");
582 }
583 } catch (Exception e) {
584 if (verbose) {
585 System.err.println("Failed to autoconfig proxy due to "+e);
586 }
587 if (trace) {
588 e.printStackTrace();
589 }
590 }
591 }
592
593 private static String decodeBase64(String inp) throws IOException {
594 return new String(Base64.getDecoder().decode(inp));
595 }
596
|
37 import java.lang.reflect.InvocationTargetException;
38 import java.lang.reflect.Method;
39 import java.net.MalformedURLException;
40 import java.net.URL;
41 import java.net.URLClassLoader;
42 import java.security.AccessController;
43 import java.security.PrivilegedAction;
44 import java.util.ArrayList;
45 import java.util.LinkedList;
46 import java.util.List;
47 import java.util.concurrent.CountDownLatch;
48 import java.util.concurrent.atomic.AtomicBoolean;
49 import java.util.concurrent.atomic.AtomicReference;
50 import java.util.jar.Attributes;
51 import java.util.jar.JarFile;
52 import java.util.jar.Manifest;
53 import java.util.Base64;
54 import com.sun.javafx.jmx.MXExtension;
55 import com.sun.javafx.runtime.SystemProperties;
56
57 public class LauncherImpl {
58
59 /**
60 * When passed as launchMode to launchApplication, tells the method that
61 * launchName is the name of the JavaFX application class to launch.
62 */
63 public static final String LAUNCH_MODE_CLASS = "LM_CLASS";
64
65 /**
66 * When passed as launchMode to launchApplication, tells the method that
67 * launchName is a path to a JavaFX application jar file to be launched.
68 */
69 public static final String LAUNCH_MODE_JAR = "LM_JAR";
70
71 // set to true to debug launch issues from Java launcher
72 private static final boolean trace = false;
73
74 // set system property javafx.verbose to true to make the launcher noisy
75 private static final boolean verbose;
76
77 private static final String MF_MAIN_CLASS = "Main-Class";
78 private static final String MF_JAVAFX_MAIN = "JavaFX-Application-Class";
377 // Save the preloader class in a static field for later use when
378 // main calls back into launchApplication.
379 savedPreloaderClass = preClass;
380
381 // If there is a public static void main(String[]) method then call it
382 // otherwise just hand off to the other launchApplication method
383
384 Exception theEx = null;
385 try {
386 Method mainMethod = tempAppClass.getMethod("main",
387 new Class[] { (new String[0]).getClass() });
388 if (verbose) {
389 System.err.println("Calling main(String[]) method");
390 }
391 savedMainCcl = Thread.currentThread().getContextClassLoader();
392 mainMethod.invoke(null, new Object[] { args });
393 return;
394 } catch (NoSuchMethodException | IllegalAccessException ex) {
395 theEx = ex;
396 savedPreloaderClass = null;
397 if (verbose) {
398 System.err.println("WARNING: Cannot access application main method: " + ex);
399 }
400 } catch (InvocationTargetException ex) {
401 ex.printStackTrace();
402 abort(null, "Exception running application %1$s", tempAppClass.getName());
403 return;
404 }
405
406 // Verify appClass extends Application
407 if (!Application.class.isAssignableFrom(tempAppClass)) {
408 abort(theEx, "JavaFX application class %1$s does not extend javafx.application.Application", tempAppClass.getName());
409 }
410 appClass = tempAppClass.asSubclass(Application.class);
411
412 if (verbose) {
413 System.err.println("Launching application directly");
414 }
415 launchApplication(appClass, preClass, args);
416 }
417
418 private static URL fileToURL(File file) throws IOException {
419 return file.getCanonicalFile().toURI().toURL();
512 if (System.getProperty("http.proxyHost") != null
513 || System.getProperty("https.proxyHost") != null
514 || System.getProperty("ftp.proxyHost") != null
515 || System.getProperty("socksProxyHost") != null) {
516 if (verbose) {
517 System.out.println("Explicit proxy settings detected. Skip autoconfig.");
518 System.out.println(" http.proxyHost=" + System.getProperty("http.proxyHost"));
519 System.out.println(" https.proxyHost=" + System.getProperty("https.proxyHost"));
520 System.out.println(" ftp.proxyHost=" + System.getProperty("ftp.proxyHost"));
521 System.out.println(" socksProxyHost=" + System.getProperty("socksProxyHost"));
522 }
523 return;
524 }
525 if (System.getProperty("javafx.autoproxy.disable") != null) {
526 if (verbose) {
527 System.out.println("Disable autoproxy on request.");
528 }
529 return;
530 }
531
532 try {
533 Class sm = Class.forName("com.sun.deploy.services.ServiceManager");
534 Class params[] = {Integer.TYPE};
535 Method setservice = sm.getDeclaredMethod("setService", params);
536 String osname = System.getProperty("os.name");
537
538 String servicename;
539 if (osname.startsWith("Win")) {
540 servicename = "STANDALONE_TIGER_WIN32";
541 } else if (osname.contains("Mac")) {
542 servicename = "STANDALONE_TIGER_MACOSX";
543 } else {
544 servicename = "STANDALONE_TIGER_UNIX";
545 }
546 Object values[] = new Object[1];
547 Class pt = Class.forName("com.sun.deploy.services.PlatformType");
548 values[0] = pt.getField(servicename).get(null);
549 setservice.invoke(null, values);
550
551 Class dps = Class.forName(
552 "com.sun.deploy.net.proxy.DeployProxySelector");
553 Method m = dps.getDeclaredMethod("reset", new Class[0]);
554 m.invoke(null, new Object[0]);
555
556 if (verbose) {
557 System.out.println("Autoconfig of proxy is completed.");
558 }
559 } catch (Exception e) {
560 if (verbose) {
561 System.err.println("Failed to autoconfig proxy due to "+e);
562 }
563 if (trace) {
564 e.printStackTrace();
565 }
566 }
567 }
568
569 private static String decodeBase64(String inp) throws IOException {
570 return new String(Base64.getDecoder().decode(inp));
571 }
572
|