How to create sample vaadin application with maven 2.2.1
Step one
--------
Create maven project with typing the following command on your command line.
mvn archetype:create -DgroupId=com.sample.vaadin -DartifactId=SampleVaadin -DarchetypeArtifactId=maven-archetype-webapp
Here is the sample pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.vaadin</groupId>
<artifactId>SampleVaadin</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleVaadin Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SampleVaadin</finalName>
</build>
</project>
Step two
--------
Integrate jetty servlet container to vaadin project
Please update your pom.xml as follows: <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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.vaadin</groupId>
<artifactId>SampleVaadin</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleVaadin Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin</artifactId>
<version>6.6.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>SampleVaadin</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
*** You can test whether jetty is running by typing "mvn jetty:run"
Step tree
--------
Writing code under src/main/java/com/sample/vaadin/HelloVaadin.java
/**
* This is the main class of the vaadin page
* @author gayan
*
* src/main/java/com/sample/vaadin/HelloVaadin.java
*/
package com.sample.vaadin;
import com.vaadin.Application;
import com.vaadin.ui.*;
public class HelloVaadin extends Application {
@Override
public void init() {
Window mainWindow = new Window("HelloVaadin");
Label label = new Label("Hello Vaadin user");
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
}
Step four
--------
Edit you web.xml file under webapp/web.xml as following
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app version="2.5" xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance\" xmlns="[http://java.sun.com/xml/ns/javaee]" xsi:schemalocation="[http://java.sun.com/xml/ns/javaee] [http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd]">
<display-name>HelloVaadin</display-name>
<context-param>
<param-name>productionMode</param-name><param-value>false</param-value><description>Vaadin production mode</description>
</context-param>
<servlet>
<servlet-name>HelloVaadin</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.sample.vaadin.HelloVaadin</param-value>
<description>Vaadin application class to start</description>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloVaadin</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
No comments:
Post a Comment