The Vaadin core library and all Vaadin add-ons are available through a Maven repository and can thereby be easily used with Apache Maven. You can use a Maven with a front-end from Eclipse or NetBeans, or by using the command-line as described in this section.
You can create a new Maven project with the following command:
$
mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-clean -DarchetypeVersion=LATEST -DgroupId=your.company
-DartifactId=project-name
-Dversion=1.0
-Dpackaging=war
The parameters are as follows:
archetypeGroupId
The group ID of the archetype is com.vaadin
for
Vaadin archetypes.
archetypeArtifactId
The archetype ID. Vaadin currently supports the following archetypes:
vaadin-archetype-clean
is a new
project with a barebone skeleton for a regular Vaadin
application. The pom.xml
includes
out-commented definitions for additional widgets.
vaadin-archetype-widget
is a skeleton
for a project with custom widgets.
vaadin-archetype-sample
is also for
project with custom widgets, but the skeleton includes
the Color Picker example used in Chapter 11, Developing New Components.
vaadin-archetype-addon
is for Vaadin add-on
projects. It packages the add-on so that it can be published
in Vaadin Directory. The archetype is for server-side add-ons
and does not include definitions needed for building a widget
set. If your add-on includes or requires other than the
widgets in the Vaadin core library, you need to copy the
required definitions from a POM of a
vaadin-archetype-clean
project.
vaadin-archetype-touchkit
is for
projects using Vaadin TouchKit, described in Chapter 19, Mobile Applications with TouchKit. Notice that this archetype uses the
AGPL-licensed version of TouchKit, which requires that
your project must also be licensed under the AGPL
license.
archetypeVersion
Version of the archetype to use. This should normally be
LATEST
.
groupId
A Maven group ID for your project. It is used for the Java package
name and should normally be your domain name reversed, such as
com.example.myproject
. The group ID is used also for
the Java source package name of your project, 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.
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 Figure 2.8, “A New Vaadin Project with vaadin-archetype-clean
”.
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:
$
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:
$
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
.
If you use Vaadin add-ons that include a widget set or make your custom widgets, you need to enable widget set compilation in the POM. The required configuration is described in Section 15.5, “Using Add-ons in a Maven Project”.