Newer
Older
gitbucket_jkp / src / main / java / JettyLauncher.java
  1. import org.eclipse.jetty.server.Server;
  2. import org.eclipse.jetty.webapp.WebAppContext;
  3.  
  4. import java.net.URL;
  5. import java.security.ProtectionDomain;
  6.  
  7. public class JettyLauncher {
  8. public static void main(String[] args) throws Exception {
  9. int port = 8080;
  10. String contextPath = "/";
  11.  
  12. for(String arg: args){
  13. if(arg.startsWith("--") && arg.contains("=")){
  14. String[] dim = arg.split("=");
  15. if(dim.length >= 2){
  16. if(dim[0].equals("--port")){
  17. port = Integer.parseInt(dim[1]);
  18. } else if(dim[0].equals("--prefix")){
  19. contextPath = dim[1];
  20. }
  21. }
  22. }
  23. }
  24.  
  25. Server server = new Server(port);
  26. WebAppContext context = new WebAppContext();
  27. ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
  28. URL location = domain.getCodeSource().getLocation();
  29.  
  30. context.setContextPath(contextPath);
  31. context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
  32. context.setServer(server);
  33. context.setWar(location.toExternalForm());
  34.  
  35. server.setHandler(context);
  36. server.start();
  37. server.join();
  38. }
  39. }