The Vaadin Wiki is temporarily in read only mode due to large recent spam attacks.

Maven instructions for the old version (6)

(Redirected from Using Vaadin with Maven)
WARNING: This wiki page was last edited over a year ago and might be outdated.

NOTE: The official up-to-date starting-point for Maven can be found at https://vaadin.com/maven  #

(This article was moved from http://dev.vaadin.com/wiki/Articles/MavenIntegration, original authors of the article can be seen from the document history).

Note that this article covers the use of Vaadin 6 with Maven. For Vaadin 7, see https://vaadin.com/wiki/-/wiki/Main/Creating+a+Maven+project.

Introduction - Scope and Purpose #

This article will show you how to use Maven2 to manage your dependencies, build your Vaadin web application, and build your custom widgetset.It is assumed that the reader is already familiar with Maven2, and that Maven2 is already installed and properly configured on the system. For specific information about Maven2, please refer to the official web site.

This page first introduces how to create a new Vaadin project with Maven2 archetypes and how to use it. Then, steps for modifying existing Maven2 projects to use Vaadin (version 6.2 or later) are given.

See the end of the page for using Vaadin versions prior to 6.2 with Maven.

Creating a Vaadin Maven project #

Create a Maven Vaadin project, for example using the archetype:

mvn archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-clean \
-DarchetypeVersion=LATEST \
-DgroupId=your.company \
-DartifactId=project-name \
-Dversion=1.0 \
-Dpackaging=war

Replace '''your.company''' with your usual groupId (if you are not familiar with the concept of groupId, please refer to the official documentation for more explanations) and '''project-name''' by the name of your project.

You can also create the project directly from IDEs with Maven integration (e.g. m2eclipse or the built-in Maven integration in NetBeans) using the archetype.

The archetype '''vaadin-archetype-clean''' contains a web project skeleton with a dependency on Vaadin and a minimal Vaadin application to use as a starting point. In addition, if necessary, you can uncomment the widgetset compilation related parts in '''pom.xml''' if using or integrating custom client side widgets.

There are also archetypes '''vaadin-archetype-sample''' and '''vaadin-archetype-widget''' which are described below.

To add Vaadin to your project without using the archetypes, you can simply add the following dependency to your pom.xml.

<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin</artifactId>
    <version>6.8.3</version>
</dependency>

Note: Vaadin 6.5.x requires GWT 2.1.0

-> You will need to update gwt-maven-plugin to 2.1.0 in pom.

-> You will need to update com.google.gwt to 2.1.0 in pom.

Running The Application #

The generated project can be easily tested using the Jetty application server with the Maven goals '''package''' '''jetty:run'''. Then navigate to '''http://localhost:8080/''myprojectname'' ''', where the project name is the artefactId used when creating the project.

To run the project using Tomcat, use the Maven goal '''tomcat:run'''.

Using Vaadin Add-ons with Maven #

The Maven POM button in the Vaadin Directory provides an easy way to use any add-on in your Maven project. See the Directory Help page for detailed instructions.

As an example, to use the ConfirmDialog add-on, edit your '''pom.xml''' as follows:

    ...
    <dependency>
      <groupId>org.vaadin.addons</groupId>
      <artifactId>confirmdialog</artifactId>
      <version>1.0.1</version>
    </dependency>
    ...
  <repository>
			<id>vaadin-addons</id>
			<url>http://maven.vaadin.com/vaadin-addons</url>
   </repository>
   ...

If the add-on contains a custom client-side widget, as is the case for most UI component add-ons, it is required to create and compile the widgetset before running the application. When using the '''vaadin-archetype-clean''' archetype, you first need to uncomment the relevant sections in your '''pom.xml''' (''gwt-maven-plugin'' and ''vaadin-maven-plugin'' configuration sections as well as the dependency on GWT and the snapshot plugin repositories). Then see the Directory Help page for detailed instructions.

To automatically find added widgets at a later time, run the goal '''vaadin:update-widgetset''' and to recompile the widgetset after updating client-side widgets or Vaadin, execute the goal '''gwt:compile'''.

Note that some add-ons in the directory have additional external dependencies, which are not listed in the automatically generated POM section in the directory. If the add-on author has not separately published the add-on with full dependency definitions in another Maven repository, you may need to add the additional dependency sections to your POM by hand.

Other Archetypes and Updating Existing Maven Projects to Use Vaadin #

Using Maven to build your custom widgets #

Generating a demo custom-widget app with the Vaadin Maven archetype #

If your project uses custom GWT widgets, you will need to compile them with the GWT compiler. This can be done using the Codehaus GWT Maven Plugin.

To set up a demo Vaadin Maven application (containing the Vaadin Color Picker demo), a Maven Archetype is available. This demo application can be used as a starting point for your own Vaadin Maven application.

Use the archetype to generate the demo project as follows:

mvn archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-sample \
-DarchetypeVersion=LATEST \
-DgroupId=your.company \
-DartifactId=project-name \
-Dversion=1.0.0 \
-Dpackaging=war

Adding custom widgets to a Vaadin Maven application #

Vaadin projects created with the above mentioned archetypes already contain the necessary definitions for compiling a widgetset.The definitions are commented out in projects created with the ''vaadin-archetype-clean'' archetype and active for projects created using the ''vaadin-archetype-sample'' or ''vaadin-archetype-widget'' archetypes. Also, an empty widgetset stub and a reference to it need to be added to the project if using ''vaadin-archetype-clean'' - see above under the add-ons section.

If the '''vaadin-maven-plugin''' is used, the widgetset (if any) can be automatically updated based on project dependencies. This is achieved with the Maven goal '''vaadin:update-widgetset''' followed by '''gwt:compile'''. Running the goal ''clean'' (or ''gwt:clean'') prior to ''vaadin:update-widgetset'' is recommended.

Creating a Vaadin widget package project #

To create and package widgets for use in other projects, use the archetype '''vaadin-archetype-widget'''. The project also contains a trivial test application for the widget.

The Maven goal '''package''' produces a JAR that can be added as a dependency to another Vaadin Maven project or otherwise distributed as a standalone widget package to other users.

Note that Vaadin widget packages contain the source code, which is needed for the GWT compiler. Only the client side sources are needed, but all sources are included by default in widget packages.

Using Vaadin nightly builds (snapshots) with Maven #

To use Vaadin nightly builds, add the Vaadin snapshot repository to your ''pom.xml'':

<project>
  ...
  <repositories>
    <repository>
      <id>vaadin-snapshots</id>
      <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

</project>

Then refer to Vaadin e.g. as '''6.3-SNAPSHOT''' or '''6.4-SNAPSHOT'''.

Note that this repository and the Vaadin add-on repository are predefined in recent versions of the Vaadin archetypes.

Using Vaadin in existing Maven projects #

Adding Vaadin to an existing Maven project #

Open the project in your IDE, and open the '''pom.xml''' file.Add the Vaadin dependency to your project:

#!xml
<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>vaadin</artifactId>
      <version>6.5.0</version>
    </dependency>
  </dependencies>
</project>

Your project can now use Vaadin. Modify your '''web.xml''' as usual to add the servlet information, and set up your Application class and you're good to go!

Adding widgetset compilation to an existing Vaadin project #

If using an older project or a project not created with the Vaadin archetypes, simply insert the following snippet into your '''pom.xml''' file. It will allow you to build your custom widgets:

#!xml
<project>
  ...
  <build>
    <plugins>
      ...
      <!-- Compiles your custom GWT components with the GWT compiler -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
	    <!-- Version 2.1.0-1 works at least with Vaadin 6.5 -->
            <version>2.1.0-1</version>
            <configuration>
                <!-- if you don't specify any modules, the plugin will find them -->
                <!--modules>
                    ..
                </modules-->
                <webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets</webappDirectory>
                <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                <runTarget>clean</runTarget>
                <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                <noServer>true</noServer>
                <port>8080</port>
                <soyc>false</soyc>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>resources</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Updates Vaadin 6.2+ widgetset definitions based on project dependencies -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
                <execution>
                    <configuration>
                        <!-- if you don't specify any modules, the plugin will find them -->
                        <!--
                        <modules>
                            <module>${package}.gwt.MyWidgetSet</module>
                        </modules>
                        -->
                    </configuration>
                    <goals>
                        <goal>update-widgetset</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

  ...

  <pluginRepositories>
    ...
    <pluginRepository>
      <id>codehaus-snapshots</id>
      <url>http://nexus.codehaus.org/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>

  ...

  <dependencies>
    ...
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>vaadin</artifactId>
      <version>6.5.0</version>
    </dependency>
    <!-- This is also used by gwt-maven-plugin to deduce GWT version number. -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>2.1.1</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

</project>

With this snippet inserted, at compile time, Maven will generate your custom widget files, and put them in the proper build directory ( ''target/artifactId-version'' ).

Archetype versions vs. Vaadin versions #

Vaadin versionArchetype - sampleArchetype - cleanArchetype - widget
6.11.0--
6.21.11.11.1
6.31.21.21.2
6.41.31.31.3
6.51.41.41.4

Only the archetype '''vaadin-archetype-sample''' versions 1.0.x are compatible with Vaadin versions prior to Vaadin 6.2.This archetype contains the color picker sample application with its own custom widget.

Most of the instructions above about adding Vaadin support to an existing Maven project also apply for older Vaadin versions. However, the Maven plugin '''vaadin-maven-plugin''' should not be used with older Vaadin versions.

0 Attachments
226958 Views
Average (4 Votes)
Comments
Short step-by-step instructions: http://vaadin.com/forum/-/message_boards/message/152693
Posted on 5/3/10 2:58 PM.
Posted on 12/31/10 12:14 AM in reply to Joonas Lehtinen.
Very usefull
but still a question..
How make compilation quickly ? and how ignore (re-compilation) of widgetset ?
Thank a lot !
Posted on 2/7/11 10:47 AM in reply to Breton B. C..
Thanks for this useful article.

Got the same problem as Carlos, I ended up binding vaadin-maven-plugin and gwt-maven-plugin executions to the "install" phase, so that compilation of widgetset is done only when I "mvn install" my project, and not every time I rebuild it during development :
<execution>
<phase>install</phase>
...
Works for me, but I'm new with Vaadin, so it may not be the proper way...
Posted on 3/6/11 12:03 AM in reply to Carlos Baeza.
@Carlos, Hugues and others: I wrote down how I 'fixed' the problem of avoiding recompilation of the widgetset using a Maven profile: http://www.jorambarrez.be/blog/2011/04/28/howto-vaadin-addon-maven/
Posted on 5/2/11 11:31 AM.
I have another scenario.
Im building a grails app. I don have maven, y only want to use an add on, but i have to recompile de widget set?
Which way is the best ?
Posted on 5/20/11 8:55 PM.
is there an example how to configure Maven to build a WAR file with Vaadin app?

I'm trying

<finalName>my-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>

<!-- War plugin: Include classpath and additional entries into MANIFEST.MF -->
<configuration>
<webappDirectory>${project.build.directory}/WebRoot</webappDirectory>
</configuration>
</plugin>

- this does not work
Posted on 9/8/11 11:28 PM.
There seems to be a problem doing a build on Hudson. Ultimately it builds OK but Hudson sees an error code return and marks the builds as failed.

Sep 26, 2011 11:10:39 AM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets
INFO: Widgetsets found from classpath:
org.vaadin.hene.popupbutton.widgetset.PopupbuttonWidgetset in jar:file:/root/.m2/repository/org/vaadin/addons/popupbutton/1.2.1/popupbutton-1.2.1.jar!/
org.vaadin.hene.splitbutton.widgetset.SplitButtonWidgetSet in jar:file:/root/.m2/repository/org/vaadin/hene/splitbutton/splitbutton/0.9.3/splitbutton-0.9.3.jar!/
com.vaadin.terminal.gwt.DefaultWidgetSet in jar:file:/root/.m2/repository/com/vaadin/vaadin/6.6.5/vaadin-6.6.5.jar!/
org.vaadin.peter.contextmenu.ContextmenuWidgetset in jar:file:/root/.m2/repository/org/vaadin/addons/contextmenu/2.2/contextmenu-2.2.jar!/

Sep 26, 2011 11:10:39 AM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets
INFO: Search took 1ms

<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0-1</version>
Posted on 9/26/11 4:52 PM in reply to Joonas Lehtinen.
Since I can't comment on the directory help page, I'll add it here:

How would we use addons with maven? The repository url you provide doesn't work and that would leave us with having to download the addons manually.
Posted on 11/29/11 9:59 AM.
At the moment running current maven commands spits out "
The desired archetype does not exist " and fails to work.

You have to specify the repository for maven to find vaadin archetypes
" -DarchetypeRepository=http://repo1.maven.org/maven2 "
Posted on 2/1/12 9:59 AM.
Super slow in Vaadin 7.0.1... it was 20 times faster in Vaadin 6.8... maybe because I am using Charts plugin?
Posted on 3/1/13 10:40 PM in reply to cuneyt ozen.