Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Adding/remove contexts at runtime?

I'm using Jetty in an embedded situation and my app allows the dynamic load/unload of plugins at runtime.
Consequently, I need to be able to load/unload contexts at runtime.

I've seen bits of documentation about the ContextProvider, but I haven't been able to figure out how to integrate that into my existing list of WebAppContext objects.

I'm currently doing my config through the API, not via XML.

---
           mServer = new Server(mPort);


            /*
             * GWT Deployment
             */
            mLog.debug("Creating jar context");
            final String warName = "Strategy.jar";
            final WebAppContext warContext = null;
            final File jar = new File(warName);
            if ((jar != null)
                && (jar.exists()))
            {
                mWarContext = new WebAppContext();
                mWarContext.setContextPath("/war");
                mWarContext.setWar(warName);
                mWarContext.setParentLoaderPriority(true);
                mContexts.add(mWarContext);
            }


            /*
             * GWT Development
             */
            mLog.debug("Creating GWT Development context");
            mDevContext = new WebAppContext();
            mDevContext.setResourceBase("./war");
            mDevContext.setContextPath("/new");
            mDevContext.setDescriptor("./war/WEB-INF/web.xml");
            mDevContext.setParentLoaderPriority(true);
            mContexts.add(mDevContext);


            mLog.debug("About to setHandlers");
final ContextHandlerCollection contexts = new ContextHandlerCollection();
            final Handler[] handlers = new Handler[mContexts.size()];
            int index = 0;
            for (final Handler curr : mContexts)
            {
                handlers[index++] = curr;
            }
            contexts.setHandlers(handlers);
            //contexts.setHandlers((Handler[]) mContexts.toArray());
            mServer.setHandler(contexts);

            // Other misc. options
            mServer.setThreadPool(new QueuedThreadPool(20));

            mServer.start();



Back to the top