Creating a Project with Maven

In previous sections, we looked into creating a Vaadin Maven project in different IDEs. In this section, we look how to create such a project on command-line. You can then import such a project in your IDE.

In addition to regular Maven, you can use any Maven-compatible build or dependency management system, such as Ivy or Gradle. For Gradle, see the Gradle Vaadin Plugin. Vaadin Plugin for Eclipse uses Ivy for resolving dependencies in Vaadin projects, and it should provide you with the basic Ivy configuration.

For an interactive guide, see the instructions at vaadin.com/maven. It automatically generates you the command to create a new project based on archetype selection. It can also generate dependency declarations for Vaadin dependencies.

Working from Command-Line

You can create a new Maven project with the following command (given in one line):

  1. $ mvn archetype:generate \
  2. -DarchetypeGroupId=com.vaadin \
  3. -DarchetypeArtifactId=vaadin-archetype-application \
  4. -DarchetypeVersion=7.x.x \
  5. -DgroupId=com.pany \
  6. -DartifactId=project-name \
  7. -Dversion=0.1 \
  8. -Dpackaging=war

The parameters are as follows:

archetypeGroupId

The group ID of the archetype is com.vaadin for Vaadin archetypes.

archetypeArtifactId

The archetype ID. See the list of available archetypes in “Overview of Maven Archetypes”.

archetypeVersion

Version of the archetype to use. This should be LATEST for normal Vaadin releases. For prerelease versions it should be the exact version number, such as 7.6.4.

groupId

A Maven group ID for your project. It is normally your organization domain name in reverse order, such as com.example. The group ID is also used as a prefix for the Java package in the sources, so it should be Java compatible - only alphanumerics and an underscore.

artifactId

Identifier of the artifact, that is, your project. The identifier may contain alphanumerics, minus, and underscore. It is appended to the group ID to obtain the Java package name for the sources. For example, if the group ID is com.example and artifact ID is myproject, the project sources would be placed in com.example.myproject package.

version

Initial version number of your application. The number must obey the Maven version numbering format.

packaging

How will the project be packaged. It is normally war.

Creating a project can take a while as Maven fetches all the dependencies. The created project structure is shown in A New Vaadin Project with Maven.

maven project created

A New Vaadin Project with Maven

Compiling and Running the Application

Before the application can be deployed, it must be compiled and packaged as a WAR package. You can do this with the package goal as follows:

  1. $ mvn package

The location of the resulting WAR package should be displayed in the command output. You can then deploy it to your favorite application server.

The easiest way to run Vaadin applications with Maven is to use the light-weight Jetty web server. After compiling the package, all you need to do is type:

  1. $ mvn jetty:run

The special goal starts the Jetty server in port 8080 and deploys the application. You can then open it in a web browser at http://localhost:8080/project-name.

Using Add-ons

If you use Vaadin add-ons from the Vaadin Directory, you need to add them as dependencies in the project POM. The instructions are given in “Using Add-ons in a Maven Project”.

In projects that use Vaadin 7.6 or older, you need to compile the widget set manually. See the add-on usage instructions.