-
-
Save samie/e2bc8f690ddd6f2fa653 to your computer and use it in GitHub Desktop.
| package org.vaadin.lightvaadin; | |
| import com.vaadin.server.VaadinServlet; | |
| import java.util.EventListener; | |
| import java.util.logging.Level; | |
| import java.util.logging.Logger; | |
| import org.eclipse.jetty.server.Server; | |
| import org.eclipse.jetty.servlet.ServletContextHandler; | |
| import org.eclipse.jetty.servlet.ServletHolder; | |
| /** Minimal Servlet bootstrap for Vaadin application. | |
| * | |
| * @author Sami Ekblad | |
| */ | |
| public class App { | |
| public static void main(String[] args) { | |
| Server server = new Server(8080); | |
| ServletContextHandler contextHandler | |
| = new ServletContextHandler(ServletContextHandler.SESSIONS); | |
| contextHandler.setContextPath("/"); | |
| ServletHolder sh = new ServletHolder(new VaadinServlet()); | |
| contextHandler.addServlet(sh, "/*"); | |
| contextHandler.setInitParameter("ui", HelloWorldUI.class.getCanonicalName()); | |
| // Register cdn.virit.in if present | |
| try { | |
| Class cls = Class.forName("in.virit.WidgetSet"); | |
| if (cls != null) { | |
| contextHandler.getSessionHandler().addEventListener((EventListener) cls.newInstance()); | |
| } | |
| } catch (Exception ex) { | |
| Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); | |
| } | |
| server.setHandler(contextHandler); | |
| try { | |
| server.start(); | |
| server.join(); | |
| } catch (Exception ex) { | |
| Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); | |
| } | |
| } | |
| } |
| package org.vaadin.lightvaadin; | |
| import com.vaadin.annotations.Theme; | |
| import com.vaadin.annotations.Title; | |
| import com.vaadin.server.VaadinRequest; | |
| import com.vaadin.ui.*; | |
| import com.vaadin.ui.Button.ClickEvent; | |
| import java.util.Date; | |
| @Title("Light Vaadin") | |
| @Theme("valo") | |
| public class HelloWorldUI extends UI { | |
| private static final long serialVersionUID = 1L; | |
| private CssLayout layout; | |
| protected void init(VaadinRequest request) { | |
| layout = new CssLayout(); | |
| setContent(layout); | |
| layout.addComponent(new Label("Hello world")); | |
| layout.addComponent(new Button("Click me", new Button.ClickListener() { | |
| @Override | |
| public void buttonClick(ClickEvent event) { | |
| Notification.show("Hello at " + new Date()); | |
| } | |
| })); | |
| } | |
| } |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>org.vaadin.directory</groupId> | |
| <artifactId>light-vaadin</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <packaging>jar</packaging> | |
| <properties> | |
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| <maven.compiler.source>1.7</maven.compiler.source> | |
| <maven.compiler.target>1.7</maven.compiler.target> | |
| <vaadin.version>7.4.2</vaadin.version> | |
| <jetty.version>9.2.3.v20140905</jetty.version> | |
| </properties> | |
| <dependencies> | |
| <dependency> | |
| <groupId>com.vaadin</groupId> | |
| <artifactId>vaadin-server</artifactId> | |
| <version>${vaadin.version}</version> | |
| <type>jar</type> | |
| <exclusions> | |
| <exclusion> | |
| <groupId>com.vaadin.external.flute</groupId> | |
| <artifactId>flute</artifactId> | |
| </exclusion> | |
| <exclusion> | |
| <groupId>com.vaadin.external.google</groupId> | |
| <artifactId>guava</artifactId> | |
| </exclusion> | |
| <exclusion> | |
| <groupId>com.vaadin</groupId> | |
| <artifactId>vaadin-sass-compiler</artifactId> | |
| </exclusion> | |
| </exclusions> | |
| </dependency> | |
| <!-- Instead of Valo, we use dawn --> | |
| <dependency> | |
| <groupId>org.peimari</groupId> | |
| <artifactId>dawn</artifactId> | |
| <version>4</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.eclipse.jetty</groupId> | |
| <artifactId>jetty-webapp</artifactId> | |
| <version>${jetty.version}</version> | |
| <type>jar</type> | |
| </dependency> | |
| </dependencies> | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>in.virit.vwscdn</groupId> | |
| <artifactId>vwscdn-maven-plugin</artifactId> | |
| <version>1.3.3</version> | |
| <executions> | |
| <execution> | |
| <phase>generate-sources</phase> | |
| <goals> | |
| <goal>generate</goal> | |
| </goals> | |
| </execution> | |
| </executions> | |
| </plugin> | |
| <plugin> | |
| <artifactId>maven-assembly-plugin</artifactId> | |
| <configuration> | |
| <archive> | |
| <manifest> | |
| <mainClass>org.vaadin.lightvaadin.App</mainClass> | |
| </manifest> | |
| </archive> | |
| <descriptorRefs> | |
| <descriptorRef>jar-with-dependencies</descriptorRef> | |
| </descriptorRefs> | |
| </configuration> | |
| <executions> | |
| <execution> | |
| <id>make-assembly</id> | |
| <phase>package</phase> | |
| <goals> | |
| <goal>single</goal> | |
| </goals> | |
| </execution> | |
| </executions> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| <repositories> | |
| <repository> | |
| <id>vaadin-addons</id> | |
| <url>http://maven.vaadin.com/vaadin-addons</url> | |
| </repository> | |
| </repositories> | |
| </project> |
This code works, but widgetset is not compiled and and there are no stiles.
Hello, I got this error:
Nov 08, 2016 8:33:34 PM dwbdip.web.jetty.App main
SEVERE: null
java.lang.ClassNotFoundException: in.virit.WidgetSet
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at dwbdip.web.jetty.App.main(App.java:29)
who can tell me which jar file i need to add?
@sunke-github, you can ignore the error, it's essentially looking for a plugin and if it finds it, it will initialize it. The error is simply there to tell you that it didn't find the plugin
Here is an upgraded version and a bit smaller size: https://github.com/amahdy/vaadin-light
I've also included some instructions on how to get it to work, and removed broken dependencies.
Thanks for sharing this code. I have some questions.