@Override
    public void start() throws Exception {
        log.finer("Initializing application.");
        watchdog.start();
        Injector injector = guiceModules.activate();
        Application app;
        if (!appBundles.isEmpty()) {
            Bundle appBundle = appBundles.get(0);
            if (!OsgiHeader.isSet(appBundle, OsgiHeader.PRIVILEGED_ACTIVATOR)) {
                osgiFramework.startBundles(appBundles, false);
            }
            List<String> header = OsgiHeader.asList(appBundle, OsgiHeader.APPLICATION);
            if (header.size() != 1) {
                throw new IllegalArgumentException("OSGi header '" + OsgiHeader.APPLICATION + "' has " + header.size() +
                                                   " entries, expected 1.");
            }
            String appName = header.get(0);
            log.finer("Loading application class " + appName + " from bundle '" + appBundle.getSymbolicName() + "'.");
            Class<Application> appClass = ContainerBuilder.safeClassCast(Application.class,
                                                                         appBundle.loadClass(appName));
            app = injector.getInstance(appClass);
        } else {
            app = injector.getInstance(Application.class);
            log.finer("Injecting instance of " + app.getClass().getName() + ".");
        }
        try {
            synchronized (appLock) {
                application = app;
                applicationInUseTracker = new ApplicationInUseTracker();
            }
            app.start();
        } catch (Exception e) {
            log.log(Level.WARNING, "Exception thrown while activating application.", e);
            synchronized (appLock) {
                application = null;
                applicationInUseTracker = null;
            }
            app.destroy();
            throw e;
        }
    }
@author Simon Thoresen Hult
@author bjorncs
jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java