Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Generating a Vaadin project in Maven archetype


Maven makes the build process really easy. Let's see how easy it is to make a new Vaadin project using Maven. We will use the latest version, Maven 3, which can be downloaded from http://maven.apache.org/download.html.

We are going to use the command line in this recipe. We will make the project in the command prompt and then we can import the Maven project into whatever IDE that supports Maven (Eclipse, IntelliJ IDEA, and so on).

Using Maven archetypes is quite handy and a quick way to create a new project. Let's try to make a new Vaadin project using the vaadin-archetype-application archetype.

For those who are new to Maven, please learn the basics from the following web page:

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

How to do it...

Carry out the following steps in order to create a new project in Maven:

  1. Open the command prompt and check whether Maven is installed properly. The version of Maven should be displayed. If not, then search the Web for how to install Maven 3 on your operating system.

    $ mvn --version
    Apache Maven 3.0.4
    Maven home: /usr/share/maven
    
  2. Decide where to put your project and run the following command. It will create a new folder called vaadin-in-maven-arch with a sample Vaadin project using the Maven file structure.

    mvn archetype:generate \
     -DarchetypeGroupId=com.vaadin \
     -DarchetypeArtifactId=vaadin-archetype-application \
     -DarchetypeVersion=LATEST \
     -Dpackaging=war \
     -DgroupId=app \
     -DartifactId=vaadin-in-maven-arch \
     -Dversion=1.0 
    
  3. Maven asks for confirmation of whether to create the project. Type y into the console. Maven will show its BUILD SUCCESS message after the project is created.

    Confirm properties configuration:
    groupId: app
    artifactId: vaadin-in-maven-arch
    version: 1.0
    package: app
     Y: : y
    
  4. Run the package Maven target in order to pack the application as a WAR file and compile the widget set. Run the following command in the root of the project.

    mvn package
    
  5. We are done and we can run our new web application. Go to the root of the project where pom.xml file is located and run the following command.

    mvn jetty:start
    

    The application will be running on http://localhost:8080.

Tip

We are using Jetty, which is open source and a commercially usable web server. Jetty is great for development because it starts really fast.

How it works...

We have made a new Vaadin application from the Maven archetype and all the content needed for running the application was generated fr us.

Let's have a look at the folder structure in the project.

Directory / Project Item

Description

pom.xml

Is a Maven configuration file. POM stands for Project Object Model.

src/main/java

Contains the entire project's Java source code.

src/main/webapp/WEB-INF

Contains web.xml, the deployment descriptor.

src/main/webapp/VAADIN

Contains a compiled widget set and can contain new Vaadin themes.

target

Used to place the output from compilation.

Maven archetype could be described as a project template. We can create our own archetypes by running the following command inside the Maven project:

mvn archetype:generate

There's more...

We can configure auto-redeploys in Jetty. The scanning interval can be set to, for example, 2 seconds. After we recompile the code, Jetty redeploys the application so we don't have to stop and start the application server after each change in the code. The following change needs to be made in the pom.xml file:

<scanIntervalSeconds>2</scanIntervalSeconds>

More about the Jetty plugin can be found on the following link:

http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin