Search in sources :

Example 1 with JavaFXNotLoadedException

use of com.codename1.impl.javase.fx.JavaFXLoader.JavaFXNotLoadedException in project CodenameOne by codenameone.

the class JavaFXLoader method runWithJavaFX.

public boolean runWithJavaFX(Class launchClass, Class mainClass, String[] args) throws JavaFXNotLoadedException, InvocationTargetException {
    if (System.getProperty("skip.fx.test", "false").equalsIgnoreCase("true")) {
        System.out.println("Skipping JavaFX auto-install");
        return false;
    }
    if (!JavaFXLoader.isJavaFXLoaded()) {
        System.out.println("JavaFX Not loaded.  Classpath=" + System.getProperty("java.class.path") + " . Adding to classpath");
        try {
            getJavaFXJarFiles();
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        Properties props = new Properties();
        boolean isJavaFX8 = "8".equals(getJavaFXVersionStr());
        try {
            String cp = System.getProperty("java.class.path");
            List<String> cpParts = new ArrayList<String>(Arrays.asList(cp.split(Pattern.quote(File.pathSeparator))));
            if (isJavaFX8 && containsJavaFX(cp)) {
                // cp = cp.replace(".codenameone/javafx/lib/*", ".codenameone/javafx8/lib/ext/*");
                ListIterator<String> lit = cpParts.listIterator();
                while (lit.hasNext()) {
                    String nex = lit.next();
                    if (containsJavaFX(nex)) {
                        lit.remove();
                    }
                }
                cp = String.join(File.pathSeparator, cpParts.toArray(new String[cpParts.size()]));
                cp += File.pathSeparator + System.getProperty("user.home") + p("/.codenameone/javafx8/lib/ext/*");
            } else if (!isJavaFX8 && containsJavaFX8(cp)) {
                // cp = cp.replace(".codenameone/javafx8/lib/ext/*", ".codenameone/javafx/lib/*");
                ListIterator<String> lit = cpParts.listIterator();
                while (lit.hasNext()) {
                    String nex = lit.next();
                    if (containsJavaFX8(nex)) {
                        lit.remove();
                    }
                }
                cp = String.join(File.pathSeparator, cpParts.toArray(new String[cpParts.size()]));
                cp += File.pathSeparator + System.getProperty("user.home") + p("/.codenameone/javafx/lib/*");
            } else if (isJavaFX8 && !containsJavaFX8(cp)) {
                cp += File.pathSeparator + System.getProperty("user.home") + p("/.codenameone/javafx8/lib/ext/*");
            } else if (!isJavaFX8 && !containsJavaFX(cp)) {
                cp += File.pathSeparator + System.getProperty("user.home") + p("/.codenameone/javafx/lib/*");
            } else {
                String javafxPath = isJavaFX8 ? System.getProperty("user.home") + p("/.codenameone/javafx8") : System.getProperty("user.home") + p("/.codenameone/javafx");
                System.err.println("Project could not be run because JavaFX is missing.  It already has JavaFX in the class path so something else must be wrong.  Ensure that the " + javafxPath + " directory exists and contains the proper files.  You may want to try just deleting the entire directory and try running this project again, as it should autonmatically re-download it.");
                System.exit(1);
            }
            props.setProperty("java.class.path", cp);
        } catch (Exception ex) {
            throw new RuntimeException("Failed to load JavaFX", ex);
        }
        updateNbProjectProperties();
        updateEclipseLaunchClasspath();
        System.out.println("Restarting JVM with JavaFX in the classpath.");
        System.out.println("NOTE: If you are trying to debug the project, you'll need to cancel this run and try running debug on the project again.  JavaFX should now be in your classpath.");
        restartJVM(launchClass, props, args);
        return true;
    }
    System.out.println("JavaFX is loaded");
    return false;
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) ListIterator(java.util.ListIterator) JavaFXNotLoadedException(com.codename1.impl.javase.fx.JavaFXLoader.JavaFXNotLoadedException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

JavaFXNotLoadedException (com.codename1.impl.javase.fx.JavaFXLoader.JavaFXNotLoadedException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ListIterator (java.util.ListIterator)1 Properties (java.util.Properties)1