1 18 19 package org.apache.activemq.web; 20 21 import org.apache.activemq.broker.BrokerService; 22 import org.apache.activemq.demo.DefaultQueueSender; 23 import org.mortbay.jetty.Connector; 24 import org.mortbay.jetty.Handler; 25 import org.mortbay.jetty.Server; 26 import org.mortbay.jetty.nio.SelectChannelConnector; 27 import org.mortbay.jetty.webapp.WebAppClassLoader; 28 import org.mortbay.jetty.webapp.WebAppContext; 29 30 31 36 public class JettyServer { 37 38 public static final int PORT = 8080; 39 40 public static final String WEBAPP_DIR = "src/main/webapp"; 41 42 public static final String WEBAPP_CTX = "/"; 43 44 public static void main(String [] args) throws Exception { 45 BrokerService broker = new BrokerService(); 47 broker.setPersistent(false); 48 broker.setUseJmx(true); 49 broker.addConnector("tcp://localhost:61616"); 50 broker.addConnector("stomp://localhost:61613"); 51 broker.start(); 52 53 DefaultQueueSender.main(new String [] {"FOO.BAR"}); 55 56 int port = PORT; 58 if (args.length > 0) { 59 String text = args[0]; 60 port = Integer.parseInt(text); 61 } 62 System.out.println("Starting Web Server on port: " + port); 63 Server server = new Server(); 64 SelectChannelConnector connector = new SelectChannelConnector(); 65 connector.setPort(port); 66 connector.setServer(server); 67 WebAppContext context = new WebAppContext(); 68 69 context.setResourceBase(WEBAPP_DIR); 70 context.setContextPath(WEBAPP_CTX); 71 context.setServer(server); 72 server.setHandlers(new Handler[]{context}); 73 server.setConnectors(new Connector[]{connector}); 74 server.start(); 75 } 76 } 77 | Popular Tags |