Newer
Older
jetty / src / main / java / Start.java

import java.awt.Desktop;
import java.net.URI;
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.FragmentConfiguration;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
import org.eclipse.jetty.webapp.WebAppConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.webapp.WebXmlConfiguration;

/**
 *
 * @author Mark George <mark.george@otago.ac.nz>
 */
public class Start {

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

		Server server = new Server(8080);

		WebAppContext context = new WebAppContext();
		context.setResourceBase("deploy");
		context.setConfigurations(
				new Configuration[]{
					new AnnotationConfiguration(),
					new WebAppConfiguration(),
					new WebXmlConfiguration(),
					new WebInfConfiguration(),
					new PlusConfiguration(),
					new MetaInfConfiguration(),
					new FragmentConfiguration(),
					new EnvConfiguration()
				}
		);


		CompletableFuture.runAsync(() -> {
			try {
				new org.h2.tools.Console().runTool("-web", "-tcp", "-browser", "-user", "sa", "-url", "jdbc:h2:./db/users;AUTO_SERVER=TRUE;IFEXISTS=TRUE");
			} catch (SQLException ex) {
				Logger.getLogger(Start.class.getName()).log(Level.SEVERE, null, ex);
			}
		});
		
		context.setContextPath("/");
		context.setParentLoaderPriority(true);
		server.setHandler(context);
		server.start();
		
		// h2 has a pretty comprehensive openBrowser method that seems more reliable than the Desktop.browse method
		org.h2.tools.Server.openBrowser("http://localhost:8080");
		
		server.join();

	}

}