Jetty deploy multiple projects Java code __jetty

Source: Internet
Author: User
Import Java.io.FileInputStream;
Import java.net.InetAddress;
Import java.net.UnknownHostException;
Import java.util.ArrayList;
Import java.util.List;
Import java.util.Properties;


Import Org.apache.log4j.Logger;
Import Org.eclipse.jetty.server.Handler;
Import Org.eclipse.jetty.server.Server;
Import org.eclipse.jetty.server.handler.HandlerCollection;
Import Org.eclipse.jetty.webapp.WebAppContext;


public class AppStart02 {

private static final String war_location = "WebApps";
private static Logger Logger = Logger.getlogger (Appstart02.class);

public static void Main (string[] args) {
Server server = new server (port);
File RootDir = new file (war_location);
List
if (!rootdir.isdirectory ()) {
}else{
string[] filelist = Rootdir.list ();
Handler[] handlerary= new handler[filelist.length];
for (int i = 0; i < filelist.length; i++) {
int index=i+1;
String Projectname=filelist[i];
Webappcontext webappcontext = new Webappcontext ();
Webappcontext.setcontextpath ("/" +projectname);
Webappcontext.setwar (war_location+ "/" +projectname);
Webappcontext.setresourcebase (war_location+ "/");
Webappcontext.setparentloaderpriority (TRUE);
Handlerary[i]=webappcontext;
}
Handlercollection HC =new handlercollection ();
Hc.sethandlers (New handler[]{webappcontext,webappcontext2});
Hc.sethandlers (handlerary);
Server.sethandler (HC);
}
try {
Server.start ();
Server.join ();
Logger.info (the Web service started successfully. IP: "+getip () +", Port: "+port";
catch (Exception e) {
E.printstacktrace ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.