To use add-ons in a project that uses Maven, you simply have to add them as dependencies in the POM. If the add-ons includes widget sets, as at least most component add-ons do, you also need to define and compile a project widget set.
Creating, compiling, and packaging a Vaadin project using Maven was described in Section 2.5, “Creating a Project with Maven”.
Vaadin Directory provides a Maven repository for all the add-ons in the Directory. You can view needed Maven dependency definitions by clicking the Figure 15.2, “Maven POM Definitions in Vaadin Directory”.
button at the right side of the add-on view, as illustrated in
You need to copy the dependency declaration to the
pom.xml
file in your project, under the
/project/dependencies
element.
... <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin</artifactId> <version>${vaadin.version}</version> </dependency> <dependency> <groupId>org.vaadin.addons</groupId> <artifactId>vaadin-sqlcontainer</artifactId> <version>1.1.0</version> </dependency> ...
You can use the exact version number, as is done in the example above, or
LATEST
to always use the latest version of the add-on.
The POM excerpt given in Directory includes also a repository definition,
but if you have used the vaadin-archetype-clean
archetype when creating your project, it should already include the
definition.
Most add-on components in Vaadin Directory include a widget set which must be compiled before using the add-on. Some add-ons, such as data binding add-ons or themes, do not include a widget set.
The configuration needed for compiling widget sets is included in the
pom.xml
created with the
vaadin-archetype-clean
archetype, but the elements are
commented out. You just need to enable the configuration.
<!-- Compile custom GWT components or widget dependencies with the GWT compiler --> <!-- <plugin> <groupId>org.codehaus.mojo</groupId> ... </plugin> --> ... <!-- <pluginRepositories> </pluginRepositories> --> ... <dependencies> ... <!-- <dependency> ... </dependency> --> </dependencies>
Your project needs a widget set that combines the default widget set
in the Vaadin core library with any widget sets from add-ons. This
requires creating an empty widget set definition
file (or module file in GWT
terminology). The actual content of the file is generated
automatically by searching the class path for widget sets (with the
vaadin:update-widgetset
as explained later), but
you need to create an empty file.
Create a widget set directory in your project source directory.
$
mkdirproject-name/src/main/java/your/company/gwt
Then create a ProjectNameWidgetSet.gwt.xml
file
in the directory with an empty <module>
element as follows:
<module> </module>
The project widget set needs to be enabled in the
web.xml
deployment descriptor in the application.
Edit the src/main/webapp/WEB-INF/web.xml
file and
add or modify the widgetset
parameter for the
servlet as follows.
<servlet>
...
<init-param>
<description>Widget Set to Use</description>
<param-name>widgetset</param-name>
<param-value>your.company.gwt.ProjectNameWidgetSet</param-value>
</init-param>
</servlet>
The parameter is the class name of the widget set, that is, without
the .gwt.xml
extension and with the Java dot
notation for class names that include the package name.
This should complete the task of enabling a widget set compilation and use in your project. Next, you need to update the project widget set, as described in the next section.
If you have enabled widget set compilation as described earlier and
created the project widget set, you need to update the widget set to
include the default widget set and any widget sets included in
add-ons. You can do this simply by running the
vaadin:update-widgetset
goal in the project directory.
$
mvnvaadin:update-widgetset
... [INFO] auto discovered modules [your.company.gwt.ProjectNameWidgetSet] [INFO] Updating widgetset your.company.gwt.ProjectNameWidgetSet [ERROR] 27.10.2011 19:22:34 com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets [ERROR] INFO: Widgetsets found from classpath: [ERROR] your.company.gwt.ProjectNameWidgetSet in file:/home/magi/itmill/maventest/project-name/src/main/java [ERROR] com.vaadin.terminal.gwt.DefaultWidgetSet in jar:file:/home/magi/.m2/repository/com/vaadin/vaadin/6.7.1/vaadin-6.7.1.jar!/ [ERROR] [ERROR] 27.10.2011 19:22:34 com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets [ERROR] INFO: Search took 8ms ...
Do not mind the "ERROR" labels, they are just an issue with the Vaadin Plugin for Maven.
If you later add other add-ons in the project, or remove some, you need to run the widget set update again.
The project widget set also needs to be compiled using the GWT
Compiler. We enabled the Maven add-ons for GWT compilation in the previous
section. You can compile the widget set with the
gwt:compile
goal as follows:
$
mvngwt:compile
You need to recompile the widget set if you upgrade to a new version of
Vaadin or any of the included widget sets. It is not
done automatically by the package
goal. If you have
added or removed add-ons, you also need to run the
vaadin:update-widgetset
goal before the compilation.
This concludes the compilation of add-on widget sets. You still need to
compile and package the actual application with the
package
goal, as described in Section 2.5, “Creating a Project with Maven”.