import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; 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.setWar("build/libs/jetty.war"); context.setConfigurations( new Configuration[]{ new AnnotationConfiguration(), new WebAppConfiguration(), new WebXmlConfiguration(), new WebInfConfiguration(), new PlusConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration(), new EnvConfiguration() } ); context.setContextPath("/shop"); context.setParentLoaderPriority(true); server.setHandler(context); server.start(); String path = context.getServletContext().getRealPath(File.separator); String dbUri = "jdbc:h2:file:" + path + "/db/users;AUTO_SERVER=TRUE;IFEXISTS=TRUE"; // // open the web console for the deployed database (comment out block if you don't want the console) // CompletableFuture.runAsync(() -> { // try { // new org.h2.tools.Console().runTool("-user", "sa", "-url", dbUri); // } catch (Exception ex) { // Logger.getLogger(Start.class.getName()).log(Level.SEVERE, null, ex); // } // }); // h2 has a pretty comprehensive openBrowser method that seems more reliable than the Desktop.browse method org.h2.tools.Server.openBrowser("http://localhost:8080/shop/"); server.join(); } }