Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

addons-maven.asciidoc 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ---
  2. title: Using Add-ons in a Maven Project
  3. order: 4
  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
  10. in the project POM. Most add-ons include a widget set, which are compiled to the
  11. project widget set.
  12. Creating, compiling, and packaging a Vaadin project with Maven was described in
  13. <<dummy/../../../framework/getting-started/getting-started-maven#getting-started.maven,"Using
  14. Vaadin with Maven">>.
  15. [[addons.maven.dependency]]
  16. == Adding a Dependency
  17. Vaadin Directory provides a Maven repository for all the add-ons in the
  18. Directory.
  19. . Open the add-on page in Vaadin Directory.
  20. . Select the version. The latest is shown by default, but you can choose another
  21. the version from the dropdown menu in the header of the add-on details page.
  22. . Click the [guilabel]#Maven/Ivy# to display the Maven dependency declaration, as
  23. illustrated in Figure <<figure.addons.maven.pombutton>>. If the add-on is
  24. available with multiple licenses, you will be prompted to select a license for
  25. the dependency.
  26. +
  27. [[figure.addons.maven.pombutton]]
  28. .Maven POM Definitions
  29. image::img/directory-maven-pom.png[]
  30. . Copy the [literal]#++dependency++# declaration to the [filename]#pom.xml# file
  31. in your project, under the [literal]#++dependencies++# element.
  32. +
  33. [subs="normal"]
  34. ----
  35. ...
  36. &lt;dependencies&gt;
  37. ...
  38. &lt;dependency&gt;
  39. &lt;groupId&gt;**com.vaadin.addon**&lt;/groupId&gt;
  40. &lt;artifactId&gt;**vaadin-charts**&lt;/artifactId&gt;
  41. &lt;version&gt;**1.0.0**&lt;/version&gt;
  42. &lt;/dependency&gt;
  43. &lt;/dependencies&gt;
  44. ----
  45. +
  46. You can use an exact version number, as is done in the example above, or
  47. [literal]#++LATEST++# to always use the latest version of the add-on.
  48. +
  49. The POM excerpt given in Directory includes also a repository definition, but if
  50. you have used the [literal]#++vaadin-archetype-application++# to create your
  51. project, it already includes the definition.
  52. . Compile the widget set as described in the following section.
  53. [[addons.maven.compiling]]
  54. == Compiling the Project Widget Set
  55. If you have used the [literal]#++vaadin-archetype-application++# to create the
  56. project, the [filename]#pom.xml# includes all necessary declarations to compile
  57. the widget set. The widget set compilation occurs in standard Maven build phase,
  58. such as with [parameter]#package# or [parameter]#install# goal.
  59. [subs="normal"]
  60. ----
  61. [prompt]#$# [command]#mvn# [parameter]#package#
  62. ----
  63. Then, just deploy the WAR to your application server.
  64. [[addons.maven.compiling.recompiling]]
  65. === Recompiling the Widget Set
  66. The Vaadin plugin for Maven tries to avoid recompiling the widget set unless
  67. necessary, which sometimes means that it is not compiled even when it should.
  68. Running the [literal]#++clean++# goal usually helps, but causes a full
  69. recompilation. You can compile the widget set manually by running the
  70. [parameter]#vaadin:compile# goal.
  71. [subs="normal"]
  72. ----
  73. [prompt]#$# [command]#mvn# [parameter]#vaadin:compile#
  74. ----
  75. Note that this does not update the project widget set by searching new widget
  76. sets from the class path. It must be updated if you add or remove add-ons, for
  77. example. You can do that by running the [literal]#++vaadin:update-widgetset++#
  78. goal in the project directory.
  79. [subs="normal"]
  80. ----
  81. [prompt]#$# [command]#mvn# [parameter]#vaadin:update-widgetset#
  82. ...
  83. [INFO] auto discovered modules [your.company.gwt.ProjectNameWidgetSet]
  84. [INFO] Updating widgetset your.company.gwt.ProjectNameWidgetSet
  85. [ERROR] 27.10.2011 19:22:34 com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getAvailableWidgetSets
  86. [ERROR] INFO: Widgetsets found from classpath:
  87. ...
  88. ----
  89. Do not mind the "ERROR" labels, they are just an issue with the Vaadin Plugin
  90. for Maven.
  91. After running the update, you need to run the [literal]#++vaadin:compile++# goal
  92. to actually compile the widget set.
  93. [[addons.maven.widgetset]]
  94. == Enabling Widget Set Compilation
  95. If you are not using a POM created with the proper Vaadin archetype, you may
  96. need to enable widget set compilation manually. The simplest way to do that is
  97. to copy the definitions from a POM created with the archetype. Specifically, you
  98. need to copy the [literal]#++plugin++# definitions. You also need the Vaadin
  99. dependencies.
  100. You need to create an empty widget set definition file, which the widget set
  101. compilation will populate with widget sets found from the class path. Create a
  102. [filename]#src/main/java/com/example/AppWidgetSet.gwt.xml# file (in the project
  103. package) with an empty [literal]#++<module>++# element as follows:
  104. ----
  105. <module>
  106. </module>
  107. ----
  108. [[addons.maven.widgetset.web]]
  109. === Enabling the Widget Set in the UI
  110. If you have previously used the default widget set in the project, you need to
  111. enable the project widget set in the [filename]#web.xml# deployment descriptor.
  112. Edit the [filename]#src/main/webapp/WEB-INF/web.xml# file and add or modify the
  113. [literal]#++widgetset++# parameter for the servlet as follows.
  114. [subs="normal"]
  115. ----
  116. &lt;servlet&gt;
  117. ...
  118. &lt;init-param&gt;
  119. &lt;description&gt;Widget Set to Use&lt;/description&gt;
  120. &lt;param-name&gt;widgetset&lt;/param-name&gt;
  121. &lt;param-value&gt;**com.example.AppWidgetSet**&lt;/param-value&gt;
  122. &lt;/init-param&gt;
  123. &lt;/servlet&gt;
  124. ----
  125. The parameter is the class name of the widget set, that is, without the
  126. [filename]#.gwt.xml# extension and with the Java dot notation for class names
  127. that include the package name.
  128. (((range="endofrange", startref="term.addons.maven")))