diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/vaadin/ivy.xml | 2 | ||||
-rw-r--r-- | java/vaadin/src/run/java/ch/asynk/Main.java | 46 |
2 files changed, 44 insertions, 4 deletions
diff --git a/java/vaadin/ivy.xml b/java/vaadin/ivy.xml index ad13fce..b1a4b3b 100644 --- a/java/vaadin/ivy.xml +++ b/java/vaadin/ivy.xml @@ -21,6 +21,6 @@ <dependency org="ch.qos.logback" name="logback-classic" rev="1.2.1"/> <dependency org="org.codehaus.janino" name="janino" rev="3.0.6"/> <dependency org="com.yahoo.platform.yui" name="yuicompressor" rev="2.4.8" conf="themes->default"/> - <dependency org="org.vaadin.jetty" name="jetty-vaadin" rev="2.0" conf="run->default"/> + <dependency org="org.eclipse.jetty" name="jetty-webapp" rev="9.4.2.v20170220" conf="run->default"/> </dependencies> </ivy-module> diff --git a/java/vaadin/src/run/java/ch/asynk/Main.java b/java/vaadin/src/run/java/ch/asynk/Main.java index cff6ee9..e0aeb15 100644 --- a/java/vaadin/src/run/java/ch/asynk/Main.java +++ b/java/vaadin/src/run/java/ch/asynk/Main.java @@ -1,14 +1,54 @@ package ch.asynk; -import org.vaadin.jetty.VaadinJettyServer; +import com.vaadin.server.DefaultUIProvider; +import com.vaadin.server.UIProvider; +import com.vaadin.server.VaadinServlet; +import com.vaadin.ui.UI; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.webapp.WebAppContext; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +class MyVaadinJettyServer extends Server +{ + public MyVaadinJettyServer(int port, Class<? extends VaadinServlet> servletClass, Class<? extends UI> uiClass, String webappDirectory) + throws IOException, InstantiationException, IllegalAccessException + { + super(port); + + createIfDoesntExists(webappDirectory); + WebAppContext context = new WebAppContext(webappDirectory, "/"); + context.addServlet(buildVaadinServlet(servletClass.newInstance(), uiClass), "/*"); + setHandler(context); + } + + private ServletHolder buildVaadinServlet(VaadinServlet servlet, Class<? extends UI> uiClass) + { + ServletHolder servletHolder = new ServletHolder(servlet); + servletHolder.setInitParameter(VaadinServlet.SERVLET_PARAMETER_UI_PROVIDER, DefaultUIProvider.class.getName()); + servletHolder.setInitParameter("UI", uiClass.getName()); + return servletHolder; + } + + private void createIfDoesntExists(String directory) throws IOException + { + Path path = Paths.get(directory); + if (!Files.exists(path)) { + Files.createDirectory(path); + } + } +} public class Main { public static void main(String[] args) throws Exception { - System.err.println("!!! org.vaadin.jetty.VaadinJettyServer uses it's own VaadinServlet instance instead of HelloWorldServlet.\n"); String webRoot = System.getProperty("WEBROOT"); if (webRoot == null) webRoot = "./src/main/WebContent/"; - new VaadinJettyServer(8080, HelloWorld.class, webRoot).start(); + new MyVaadinJettyServer(8081, HelloWorldServlet.class, HelloWorld.class, webRoot).start(); } } |