You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addons-maven.asciidoc 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. ---
  2. title: Using Add-ons in a Maven Project
  3. order: 2
  4. layout: page
  5. ---
  6. [[addons.maven]]
  7. = Using Add-ons in a Maven Project
  8. ((("Maven", "using add-ons", id="term.addons.maven", range="startofrange")))
  9. To use add-ons in a Maven project, you simply have to add them as dependencies in the project POM.
  10. Most add-ons include client-side widgets, counterparts of the server-side components.
  11. The add-on widgets will be included and compiled into the _application widget set_.
  12. Compiling the widget set is handled by the Vaadin Maven Plugin.
  13. It is enabled in Maven projects created from the Vaadin archetypes, as described in <<../getting-started/getting-started-overview#getting-started.overview, "Getting Started">>.
  14. The plugin will attempt to automatically detect if you need to compile the application widget set.
  15. It will generate a [filename]#target/generated-sources/gwt/AppWidgetset.gwt.xml# widget set descriptor, update it when necessary, and use it for compiling the widget set.
  16. [[addons.maven.dependency]]
  17. == Adding a Dependency
  18. Vaadin Directory provides a Maven repository for all the add-ons in the
  19. Directory.
  20. . Open the add-on page in Vaadin Directory.
  21. . Choose the version on the _left-side menu bar_.
  22. +
  23. image::img/directory-version.png[width=60%, scaledwidth=80%]
  24. +
  25. The latest version is selected by default, but you can choose another version from the drop-down menu.
  26. . Click [guilabel]#Install# to display the dependency declarations.
  27. +
  28. image::img/directory-install.png[width=50%, scaledwidth=70%]
  29. +
  30. If the add-on is available with multiple licenses, you will be prompted to select a license for the dependency.
  31. . Select the [guilabel]#Maven# tab.
  32. +
  33. image::img/directory-maven-pom.png[width=50%, scaledwidth=70%]
  34. . Open the [filename]#pom.xml# file.
  35. In single-module projects, you only have one, located in the root folder of the project.
  36. In multi-module projects, open the one in your Vaadin application module.
  37. *Eclipse IDE*:: Right-click on the [filename]#pom.xml# file and select "Open With > XML Editor".
  38. You can also left-click it, which opens the Maven POM editor, but directly editing the XML code is usually easier.
  39. You can also use the XML editor tab of the POM editor.
  40. . Copy and paste the [literal]#dependency# declaration to under the [literal]#++dependencies++# element.
  41. +
  42. [source, xml, subs="normal"]
  43. ----
  44. ...
  45. <dependencies>
  46. ...
  47. <dependency>
  48. <groupId>[replaceable]#com.vaadin.addon#</groupId>
  49. <artifactId>[replaceable]#vaadin-charts#</artifactId>
  50. <version>[replaceable]#1.0.0#</version>
  51. </dependency>
  52. </dependencies>
  53. ----
  54. +
  55. You can use an exact version number, as is done in the example above, or [literal]#++LATEST++# to always use the latest version of the add-on.
  56. +
  57. The POM excerpt given in Directory includes also a `repository` definition, but if you have used the Vaadin archetypes to create your project, it already includes the definition.
  58. . _For commercial add-ons_, you need a license key.
  59. +
  60. Click [guilabel]#Activate# to buy a license, obtain a trial license key, or get the key from your Pro Tools subscription.
  61. +
  62. image::img/directory-activate.png[width=50%, scaledwidth=70%]
  63. +
  64. For official Vaadin add-ons, see <<addons-cval#addons.cval, "Installing Commercial Vaadin Add-on License">> for more information.
  65. . _In Vaadin 7.6 and older_: You need to configure the widget set as described in <<addons.maven.compiling>>.
  66. [[addons.maven.compiling]]
  67. == Configuring the Application Widget Set
  68. [NOTE]
  69. ====
  70. The widget set is automatically configured in Vaadin 7.7 and later.
  71. The plugin will attempt to detect any add-ons that need the widget set to be compiled.
  72. Just note that it can take a bit time to compile.
  73. To speed up, instead of compiling it locally, you can also use a public cloud service to compile it for you, and use it directly from a CDN service.
  74. See <<addons.maven.modes>> for instructions.
  75. ====
  76. In projects that use Vaadin 7.6 or older, you need to manually configure the widget set as follows.
  77. [[addons.maven.widgetset]]
  78. === Configuring Widget Set Compilation
  79. Compiling the widget set in Maven projects requires the Vaadin Maven plugin.
  80. It is included in Maven projects created with a current Vaadin archetype.
  81. If all is well, you are set to go.
  82. If you have used the Vaadin archetypes to create the project, the POM should include all necessary declarations to compile the widget set.
  83. However, if your Maven project has been created otherwise, you may need to enable widget set compilation manually.
  84. The simplest way to do that is to copy the definitions from a POM created with the archetype.
  85. Specifically, you need to copy the `vaadin-maven-plugin` definition in the `plugin` section, as well as the Vaadin dependencies and any relevant settings.
  86. === Compiling the Widget Set
  87. The widget set compilation occurs in standard Maven build phase, such as with [parameter]#package# or [parameter]#install# goal.
  88. *Eclipse IDE*::
  89. Click the *Compile Vaadin Widgetset* button in the Eclipse toolbar.
  90. +
  91. image::img/widgetset-compiling-toolbar.png[width=50%, scaledwidth=60%]
  92. *Command-line*::
  93. Simply run the `package` goal.
  94. +
  95. [subs="normal"]
  96. ----
  97. [prompt]#$# [command]#mvn# package
  98. ----
  99. +
  100. Then, just deploy the WAR to your application server.
  101. [[addons.maven.compiling.recompiling]]
  102. === Recompiling the Widget Set
  103. The Vaadin plugin for Maven tries to avoid recompiling the widget set unless
  104. necessary, which sometimes means that it is not compiled even when it should.
  105. Running the [literal]#++clean++# goal usually helps, but causes a full
  106. recompilation. You can compile the widget set manually by running the
  107. [parameter]#vaadin:compile# goal.
  108. *Eclipse IDE*::
  109. Click the *Compile Vaadin Widgetset* button in the Eclipse toolbar.
  110. *Command-line*::
  111. Run the `vaadin:compile` goal.
  112. +
  113. [subs="normal"]
  114. ----
  115. [prompt]#$# [command]#mvn# vaadin:compile
  116. ----
  117. === Updating the Widget Set
  118. Note that the `vaadin:compile` goal does not update the project widget set by searching new widget sets from the class path.
  119. It must be updated when you, for example, add or remove add-ons.
  120. You can do that by running the [literal]#vaadin:update-widgetset# goal in the project directory.
  121. [subs="normal"]
  122. ----
  123. [prompt]#$# [command]#mvn# [parameter]#vaadin:update-widgetset#
  124. ...
  125. [INFO] auto discovered modules [your.company.gwt.ProjectNameWidgetSet]
  126. [INFO] Updating widgetset your.company.gwt.ProjectNameWidgetSet
  127. [ERROR] 27.10.2011 19:22:34 com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets
  128. [ERROR] INFO: Widgetsets found from classpath:
  129. ...
  130. ----
  131. Do not mind the "ERROR" labels, they are just an issue with the Vaadin Plugin
  132. for Maven.
  133. After running the update, you need to run the [literal]#++vaadin:compile++# goal
  134. to actually compile the widget set.
  135. [[addons.maven.modes]]
  136. == Widget Set Modes
  137. The application widget set is by default compiled locally.
  138. You can also have it compiled in a public cloud service provided by Vaadin, and either use it directly from a CDN service or download it to serve it from your development server.
  139. .Widget set modes
  140. image::img/widgetset-modes.png[width=80%, scaledwidth=100%]
  141. The widget set mode, defined in the project POM, determines how the widget set is compiled.
  142. `local` (default)::
  143. The widget set is compiled locally in your development workstation.
  144. `cdn`::
  145. Compilation is done in the public cloud service.
  146. It is served directly from the CDN (Content Delivery Network) service.
  147. +
  148. Using CDN is recommended for development.
  149. `fetch`::
  150. Compilation is done in the public cloud service.
  151. The widget set is then downloaded and deployed with the rest of the application to the application server.
  152. The mode is set with a `vaadin.widgetset.mode` property in the [elementname]#properties# section at the beginning of the project POM.
  153. [[addons.maven.modes.local]]
  154. === Local Widget Set Compilation
  155. If add-ons are detected, an [filename]#AppWidgetset.gwt.xml# descriptor file is generated into the [filename]#generated-resources# folder, and later updated automatically.
  156. The compiler uses the descriptor to compile the widget set, which is included in the web application archive.
  157. .Local widget set compilation
  158. image::img/widgetset-mode-local.png[width=80%, scaledwidth=60%]
  159. Local compilation is needed in projects that have custom widgets or widget sets that are not available from the Maven central repository or from the Vaadin add-ons or pre-releases repositories.
  160. Local compilation is necessary for completely offline work.
  161. Local compilation is currently the default mode.
  162. It is therefore not necessary to set it explicitly, unless you have made global Maven settings and want to override them in a particular project.
  163. You can set the `local` parameter in the [elementname]#properties# section of your [filename]#pom.xml#:
  164. [source, xml]
  165. ----
  166. <properties>
  167. ...
  168. <vaadin.widgetset.mode>local</vaadin.widgetset.mode>
  169. </properties>
  170. ...
  171. ----
  172. [[addons.maven.modes.cdn]]
  173. === Online Widget Set Compilation and CDN
  174. The online compilation service makes it easier to use add-on components in Vaadin applications, by avoiding compilation of widget sets locally.
  175. It caches the widget sets, so often one is available immediately.
  176. A widget set can combine widgets from multiple add-ons and if a particular combination does not already exist, the service automatically compiles it.
  177. .Online widget set compilation and CDN
  178. image::img/widgetset-mode-cdn.png[width=80%, scaledwidth=100%]
  179. The CDN (Content Delivery Network) is a global network of web servers that serve the cached widget sets directly when you load your application in your browser.
  180. Avoiding local compilation can speed up development significantly.
  181. In development teams, all can use the shared widget sets immediately.
  182. [TIP]
  183. ====
  184. While this gives benefits, the application will not work without online connnectivity.
  185. When you need to avoid the demo effect, either use the `local` or `fetch` mode.
  186. ====
  187. The cloud service compiles a widget set with a given Vaadin version and a list of add-ons installed in your project.
  188. The Maven plug-in receives a public URL where the widget set is available and generates an [filename]#AppWidgetset.java# file that configures your application to use the online version.
  189. The file is generated to the default Java package.
  190. [NOTE]
  191. ====
  192. Online compilation and CDN can only be used with publicly available add-ons.
  193. This means that the add-on dependencies must be available in the Maven central repository or in the Vaadin add-ons or pre-releases repositories.
  194. If you have custom widget implementations or non-public add-ons in your sources, you cannot use the online compilation and CDN service.
  195. ====
  196. ==== Enabling Compilation
  197. To enable online compilation and delivery from the CDN, set the widget set mode to `cdn` in the [elementname]#properties# section of your [filename]#pom.xml#:
  198. [source, xml]
  199. ----
  200. <properties>
  201. ...
  202. <vaadin.widgetset.mode>cdn</vaadin.widgetset.mode>
  203. </properties>
  204. ...
  205. ----
  206. When using the online compilation service, a [interfacename]#WidgetsetInfo# implementation is generated for your project; this makes it possible for your application to find the widget set from the correct location.
  207. [NOTE]
  208. ====
  209. *The CDN is not meant to be used in production.*
  210. It is are meant for speeding up development for yourself and your team.
  211. It is also useful if you maintain your source code in GitHub or a similar service, so that your globally working development team can immediately use the widget sets without need to compile them.
  212. For production, especially in intranet applications, you should normally use the `local` or `fetch` modes.
  213. This ensures that separating the availability of the Vaadin CDN service from availability of the application server does not add an extra point of failure.
  214. _They can be used for production_ if your application is intended as globally available, you want to gain the global delivery benefit of the Vaadin CDN, and the availability tradeoff is not significant.
  215. ====
  216. === Serving Remotely Compiled Widget Set Locally
  217. If you want to use online compilation, but still serve the files as part of your application, you can use the `fetch` mode.
  218. .Fetching online widget set compilation
  219. image::img/widgetset-mode-fetch.png[width=80%, scaledwidth=100%]
  220. The Maven plugin downloads the compiled widget set into the project as it was compiled locally.
  221. It generates an [classname]#AppWidgetset# class and used to provide a correct URL to the locally stored widget set.
  222. To enable the fetch mode, in the [elementname]#properties# section of your [filename]#pom.xml#:
  223. [source, xml]
  224. ----
  225. <properties>
  226. ...
  227. <vaadin.widgetset.mode>fetch</vaadin.widgetset.mode>
  228. </properties>
  229. ...
  230. ----
  231. // TODO This is recommended during development, as it avoids slow local compilation and typically.
  232. (((range="endofrange", startref="term.addons.maven")))