THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block |
---|
package com.smarttrust.cd.mysp.tpm; import org.grlea.log.SimpleLogger; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; import org.mortbay.jetty.bio.SocketConnector; import org.mortbay.jetty.webapp.WebAppContext; public class Start { private static final SimpleLogger log = new SimpleLogger(Start.class); /** * Main function, starts the Jetty 6 server. * * @param args */ public static void main(String[] args) { Server jettyServer = null; try { jettyServer = new Server(); SocketConnector conn = new SocketConnector(); conn.setPort(8080); jettyServer.setConnectors(new Connector[]{conn}); WebAppContext wah = new WebAppContext(); wah.setContextPath("/myapp"); wah.setWar("src/main/webapp"); jettyServer.setHandler(wah); jettyServer.start(); } catch (Exception e) { log.fatal("Could not start the Jetty server: " + e); if (jettyServer != null) { try { jettyServer.stop(); } catch (Exception e1) { log.fatal("Unable to stop the jetty server: " + e1); } } } } } |
SSL version of the above
A keystore is needed (can be generated with $JAVA_HOME/bin/keytool -genkey -keystore keystore).
Code Block |
---|
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class StartSsl {
public static void main(String[] args) {
String password = System.getProperty("keystorepassword", "jetty6");
String keystore = System.getProperty("keystore", "src/main/resources/keystore");
String war = System.getProperty("warpath", "src/main/webapp");
String contextPath = System.getProperty("contextpath", "/");
int sslPort = Integer.parseInt(System.getProperty("port", "8443"));
Server jettyServer = null;
try {
jettyServer = new Server();
SslSocketConnector sslConn = new SslSocketConnector();
sslConn.setPort(sslPort);
sslConn.setPassword(password);
sslConn.setKeystore(keystore);
jettyServer.setConnectors(new Connector[] { sslConn });
WebAppContext wah = new WebAppContext();
wah.setContextPath(contextPath);
wah.setWar(war);
jettyServer.setHandler(wah);
jettyServer.start();
} catch (Exception e) {
System.out.println("Could not start the Jetty server: " + e);
if (jettyServer != null) {
try {
jettyServer.stop();
} catch (Exception e1) {
System.out.println("Unable to stop the jetty server: " + e1);
}
}
}
}
}
|