Jetty embedded multiple projects

Today, I will embed a web project in the connectionManager in openfire and provide JS api

Use the ContextHandlerCollection object to add multiple web projects

package hb.jetty;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.webapp.WebAppContext;

public class JettyMoreServers {

public static void main(String[] args) throws Exception {

Server server = new Server(8080);

ContextHandlerCollection contexts = new ContextHandlerCollection();

//Get the root directory of the project
String relativelyPath=System.getProperty("user.dir");

//Add the first web project, the name is manager
WebAppContext context = new WebAppContext();
        context.setContextPath("/manager");
        context.setDescriptor(relativelyPath + "/jetty/webapps/manager/WEB-INF/web.xml");
        context.setResourceBase(relativelyPath + "/jetty/webapps/manager");
        context.setParentLoaderPriority(true);
        
        //Use the context list to add multiple contexts, that is, multiple web projects
        contexts.addHandler(context);
        
        //Add a second web project, the name is manager
        WebAppContext context2 = new WebAppContext();
        context2.setContextPath("/myweb");
        context2.setDescriptor(relativelyPath + "/jetty/webapps/myweb/WEB-INF/web.xml");
        context2.setResourceBase(relativelyPath + "/jetty/webapps/myweb");
        context2.setParentLoaderPriority(true);
        //Use the context list to add multiple contexts, that is, multiple web projects
        contexts.addHandler(context2);

        server.setHandler(contexts);

        server.start();
        server.join();
}

}

Today, I will embed a web project in the connectionManager in openfire and provide JS api

Use the ContextHandlerCollection object to add multiple web projects

package hb.jetty;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.webapp.WebAppContext;

public class JettyMoreServers {

public static void main(String[] args) throws Exception {

Server server = new Server(8080);

ContextHandlerCollection contexts = new ContextHandlerCollection();

//Get the root directory of the project
String relativelyPath=System.getProperty("user.dir");

//Add the first web project, the name is manager
WebAppContext context = new WebAppContext();
        context.setContextPath("/manager");
        context.setDescriptor(relativelyPath + "/jetty/webapps/manager/WEB-INF/web.xml");
        context.setResourceBase(relativelyPath + "/jetty/webapps/manager");
        context.setParentLoaderPriority(true);
        
        //Use the context list to add multiple contexts, that is, multiple web projects
        contexts.addHandler(context);
        
        //Add a second web project, the name is manager
        WebAppContext context2 = new WebAppContext();
        context2.setContextPath("/myweb");
        context2.setDescriptor(relativelyPath + "/jetty/webapps/myweb/WEB-INF/web.xml");
        context2.setResourceBase(relativelyPath + "/jetty/webapps/myweb");
        context2.setParentLoaderPriority(true);
        //Use the context list to add multiple contexts, that is, multiple web projects
        contexts.addHandler(context2);

        server.setHandler(contexts);

        server.start();
        server.join();
}

}

Leave a Comment

Your email address will not be published.