Having trouble with Embedding Mozilla

"J.J. Zhuang" <[email protected]>
Newsgroups gmane.comp.mozilla.devel.oji
Message-ID <[email protected]>
I'm trying out embedding mozilla in my java program.  I followed the example give at this URL:

http://developer.mozilla.org/en/docs/JavaXPCOM:Embedding_Mozilla_in_a_Java_Application_using_JavaXPCOM

Here's my code:

public class SimpleLauncher {

    public static class LocationProvider implements IAppFileLocProvider {

        File grePath;

        public LocationProvider(File grePath) {
            this.grePath = grePath;
        }

        public File getFile(String aProp, boolean[] aPersistent) {
            System.out.println(aProp);
            System.out.println(aPersistent);

            File file = null;
            if (aProp.equals("GreD") || aProp.equals("GreComsD")) {
                file = grePath;
                if (aProp.equals("GreComsD")) {
                    file = new File(file, "components");
                }
            } else if (aProp.equals("MozBinD") || aProp.equals("CurProcD")
                    || aProp.equals("ComsD") || aProp.equals("ProfD")) {
                file = grePath;
                if (aProp.equals("ComsD")) {
                    file = new File(file, "components");
                }
            }
            return file;
        }

        public File[] getFiles(String aProp) {
            System.out.println(aProp);

            File[] files = null;
            if (aProp.equals("APluginsDL")) {
                files = new File[1];
                files[0] = new File(grePath, "plugins");
            }
            return files;
        }
    }

   public static void main(String[] args) {

        Mozilla mozilla = Mozilla.getInstance();
        GREVersionRange[] range = new GREVersionRange[1];
        range[0] = new GREVersionRange("1.8.0", true, "1.9", false);
        // work with trunk nightly version 1.9a1

        try {
            File grePath = Mozilla.getGREPathWithProperties(range, null);
            System.out.println(grePath.toString());

            mozilla.initialize(grePath);
            LocationProvider locProvider = new LocationProvider(grePath);
            mozilla.initEmbedding(grePath, grePath, locProvider);

            // Now we need to start an XUL application, so we get an instance of
            // the
            // XPCOM service manager
            nsIServiceManager serviceManager = mozilla.getServiceManager();

            // Now we need to get the @mozilla.org/toolkit/app-startup;1
            // service:
            nsIAppStartup appStartup = (nsIAppStartup) serviceManager
                    .getServiceByContractID(
                            "@mozilla.org/toolkit/app-startup;1",
                            nsIAppStartup.NS_IAPPSTARTUP_IID);

            // Get the nsIWindowWatcher interface to the above
            nsIWindowCreator windowCreator = (nsIWindowCreator) appStartup
                    .queryInterface(nsIWindowCreator.NS_IWINDOWCREATOR_IID);

            // Get the window watcher service
            nsIWindowWatcher windowWatcher = (nsIWindowWatcher) serviceManager
                    .getServiceByContractID(
                            "@mozilla.org/embedcomp/window-watcher;1",
                            nsIWindowWatcher.NS_IWINDOWWATCHER_IID);

            // Set the window creator (from step 6)
            windowWatcher.setWindowCreator(windowCreator);

            // Create the root XUL window:
            nsIDOMWindow win = windowWatcher.openWindow(null,
                    "chrome://your-app/content/window.xul", "mywindow",
                    "chrome,resizable,centerscreen", null);

            // Set this as the active window
            windowWatcher.setActiveWindow(win);

            // Hand over the application to xpcom/xul, this will block:
            appStartup.run();

        } catch (FileNotFoundException e) {
            // this exception is thrown if greGREPathWithProperties cannot find
            // a GRE
        } catch (XPCOMException e) {
            // this exception is thrown if initEmbedding failed
        }

    }
}

I can see that the correct xulrunner is found and the LocationProvider.getFile() is being called.  Obviously the url "chrome://your-app/content/window.xul" should be replaced with something real.  But no matter what I try nothing happens.  I don't see any window popping up.  I'm on Mac OS X and have not tried this on Windows.  Has anyone ever got this to work following the instructions?

Thanks for your  help!

J.J. Zhuang
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.