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.

gwt-addons.asciidoc 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ---
  2. title: Creating Add-ons
  3. order: 11
  4. layout: page
  5. ---
  6. [[gwt.addons]]
  7. = Creating Add-ons
  8. ((("add-ons", "creating", id="term.gwt.addons", range="startofrange")))
  9. Add-ons are the most convenient way to reuse Vaadin code, either commercially or
  10. free. Vaadin Directory serves as the store for the add-ons. You can distribute
  11. add-ons both as JAR libraries and Zip packages.
  12. Creating a typical add-on package involves the following tasks:
  13. * Compile server-side classes
  14. * Compile JavaDoc (optional)
  15. * Build the JAR
  16. ** Include Vaadin add-on manifest
  17. ** Include the compiled server-side classes
  18. ** Include the compiled JavaDoc (optional)
  19. ** Include sources of client-side classes for widget set compilation (optional)
  20. ** Include any JavaScript dependency libraries (optional)
  21. ** Exclude any test or demo code in the project
  22. The exact contents depend on the add-on type. Component add-ons often include a
  23. widget set, but not always, such as JavaScript components or pure server-side
  24. components. You can also have data container and theme add-ons, as well as
  25. various tools.
  26. It is common to distribute the JavaDoc in a separate JAR, but you can also
  27. include it in the same JAR.
  28. [[gwt.addons.export]]
  29. == Exporting Add-on in Eclipse
  30. If you use the Vaadin Plugin for Eclipse for your add-on project, you can simply
  31. export the add-on from Eclipse.
  32. . Select the project and then "File > Export" from the menu
  33. . In the export wizard that opens, select "Vaadin > Vaadin Add-on Package", and
  34. click [guibutton]#Next#
  35. . In the [guilabel]#Select the resources to export# panel, select the content that
  36. should be included in the add-on package. In general, you should include sources
  37. in [filename]#src# folder (at least for the client-side package), compiled
  38. server-side classes, themes in [filename]#WebContent/VAADIN/themes#. These are
  39. all included automatically. You probably want to leave out any demo or example
  40. code.
  41. +
  42. [[figure.gwt.addons.export]]
  43. .Exporting a Vaadin Add-on
  44. image::img/addon-export.png[]
  45. +
  46. If you are submitting the add-on to Vaadin Directory, the
  47. [guilabel]#Implementation title# should be exactly the name of the add-on in
  48. Directory. The name may contain spaces and most other letters. Notice that __it
  49. is not possible to change the name later__.
  50. +
  51. The [guilabel]#Implementation version# is the version of your add-on. Typically
  52. experimental or beta releases start from 0.1.0, and stable releases from 1.0.0.
  53. +
  54. The [guilabel]#Widgetsets# field should list the widget sets included in the
  55. add-on, separated by commas. The widget sets should be listed by their class
  56. name, that is, without the [filename]#.gwt.xml# extension.
  57. +
  58. The [guilabel]#JAR file# is the file name of the exported JAR file. It should
  59. normally include the version number of the add-on. You should follow the Maven
  60. format for the name, such as [filename]#myaddon-1.0.0.jar#.
  61. +
  62. Finally, click [guibutton]#Finish#.
  63. ifdef::web[]
  64. [[gwt.addons.ant]]
  65. == Building Add-on with Ant
  66. Building an add-on with Ant is similar to building Vaadin applications. Vaadin
  67. libraries and other dependencies are retrieved and included in the classpath
  68. using Apache Ivy.
  69. In the following, we assume the same structure as in the Eclipse project
  70. example. Let us put the build script in the [filename]#build# folder under the
  71. project. We begin the Ant script as follows:
  72. [subs="normal"]
  73. ----
  74. <?xml version="1.0"?>
  75. <project xmlns:ivy="antlib:org.apache.ivy.ant"
  76. name="**My Own add-on**"
  77. basedir=".."
  78. default="package-jar">
  79. ----
  80. The namespace declaration is all you need to do to enable Ivy in Ant 1.6 and
  81. later. For earlier Ant versions, please see the Ivy documentation.
  82. [[gwt.addons.ant.configuration]]
  83. === Configuration and Initialization
  84. In the example script, we organize most settings in a [literal]#++configure++#
  85. target and then initialize the build in [literal]#++init++# target.
  86. [subs="normal"]
  87. ----
  88. //Update these settings for your project structure
  89. <target name="configure">
  90. <!-- Where project source files are located -->
  91. <property name="src-location" value="**src**" />
  92. <!-- Name of the widget set. -->
  93. <property name="widgetset" value="**com.example.myaddon.widgetset.MyAddonWidgetset**"/>
  94. <!-- Addon version -->
  95. <property name="version" value="**0.1.0**"/>
  96. <!-- Compilation result directory -->
  97. <property name="result-dir" value="build/result"/>
  98. <!-- The target name of the built add-on JAR -->
  99. <property name="target-jar"
  100. value="${result-dir}/**myaddon**-${version}.jar"/>
  101. </target>
  102. //Initialize build
  103. <target name="init" depends="configure">
  104. <!-- Construct and check classpath -->
  105. <path id="compile.classpath">
  106. <pathelement path="build/classes" />
  107. <pathelement path="${src-location}" />
  108. <fileset dir="${result-dir}/lib">
  109. <include name="*.jar"/>
  110. </fileset>
  111. </path>
  112. <mkdir dir="${result-dir}"/>
  113. </target>
  114. ----
  115. You will need to make some configuration also in the [literal]#++package-jar++#
  116. target in addition to the [literal]#++configure++# target.
  117. [[gwt.addons.ant.compiling]]
  118. === Compiling the Server-Side
  119. Compiling the add-on requires the Vaadin libraries and any dependencies. We use
  120. Apache Ivy for resolving the dependencies and retrieving the library JARs.
  121. ----
  122. <!-- Retrieve dependencies with Ivy -->
  123. <target name="resolve" depends="init">
  124. <ivy:retrieve
  125. pattern="${result-dir}/lib/[artifact].[ext]"/>
  126. </target>
  127. ----
  128. The [literal]#++pattern++# attribute for the [literal]#++<retrieve>++# task
  129. specifies where the dependencies are stored, in the above case in the
  130. [filename]#build/result/lib# directory.
  131. Compiling the server-side classes is then straight-forward:
  132. ----
  133. <!-- Compile server-side -->
  134. <target name="compile-server-side"
  135. depends="init, resolve">
  136. <delete dir="${result-dir}/classes"/>
  137. <mkdir dir="${result-dir}/classes"/>
  138. <javac srcdir="${src-location}"
  139. destdir="${result-dir}/classes">
  140. <classpath>
  141. <path refid="compile.classpath"/>
  142. </classpath>
  143. </javac>
  144. </target>
  145. ----
  146. [[gwt.addons.ant.javadoc]]
  147. === Compiling the JavaDoc
  148. You may want to include API documentation for the add-on in the same or in a
  149. different JAR file. You can do it as follows, using the configuration we defined
  150. earlier. You may want to exclude the client-side classes and any test and demo
  151. classes from the JavaDoc, as is done in this example, if they are in the same
  152. source tree.
  153. [subs="normal"]
  154. ----
  155. &lt;!-- Compile JavaDoc --&gt;
  156. &lt;target name="compile-javadoc" depends="init"&gt;
  157. &lt;delete dir="${result-dir}/javadoc"/&gt;
  158. &lt;mkdir dir="${result-dir}/javadoc"/&gt;
  159. &lt;javadoc destdir="${result-dir}/javadoc"&gt;
  160. &lt;sourcefiles&gt;
  161. &lt;fileset dir="${src-location}" id="src"&gt;
  162. &lt;include name="**/*.java"/&gt;
  163. &lt;!-- Excluded stuff from the package --&gt;
  164. &lt;exclude name="**++*++++*++/client/++*++++*++/++*++**"/&gt;
  165. &lt;exclude name="**++*++++*++/demo/++*++++*++/++*++**"/&gt;
  166. &lt;exclude name="**++*++++*++/MyDemoUI.java**"/&gt;
  167. &lt;/fileset&gt;
  168. &lt;/sourcefiles&gt;
  169. &lt;classpath&gt;
  170. &lt;path refid="compile.classpath"/&gt;
  171. &lt;/classpath&gt;
  172. &lt;/javadoc&gt;
  173. &lt;/target&gt;
  174. ----
  175. [[gwt.addons.ant.package]]
  176. === Packaging the JAR
  177. An add-on JAR typically includes the following:
  178. * Vaadin add-on manifest
  179. * The compiled server-side classes
  180. * The compiled JavaDoc (optional)
  181. * Sources of client-side classes (optional)
  182. * Any JavaScript dependency libraries (optional)
  183. Let us begin crafting the target. The JAR requires the compiled server-side
  184. classes and the optional API documentation.
  185. ----
  186. <!-- Build the JAR -->
  187. <target name="package-jar"
  188. depends="compile-server-side, compile-javadoc">
  189. <jar jarfile="${target-jar}" compress="true">
  190. ----
  191. First, you need to include a manifest that defines basic information about the
  192. add-on. The implementation title must be the exact title of the add-on, as shown
  193. in the Vaadin Directory title. The vendor is you. The manifest also includes the
  194. license title and file reference for the add-on.
  195. [subs="normal"]
  196. ----
  197. &lt;!-- Manifest required by Vaadin Directory --&gt;
  198. &lt;manifest&gt;
  199. &lt;attribute name="Vaadin-Package-Version"
  200. value="1" /&gt;
  201. &lt;attribute name="Vaadin-Widgetsets"
  202. value="${widgetset}" /&gt;
  203. &lt;attribute name="Implementation-Title"
  204. value="**My Own Addon**" /&gt;
  205. &lt;attribute name="Implementation-Version"
  206. value="${version}" /&gt;
  207. &lt;attribute name="Implementation-Vendor"
  208. value="**Me Myself**" /&gt;
  209. &lt;attribute name="Vaadin-License-Title"
  210. value="**Apache2**" /&gt;
  211. &lt;attribute name="Vaadin-License-File"
  212. value="**http://www.apache.org/licenses/LICENSE-2.0**" /&gt;
  213. &lt;/manifest&gt;
  214. ----
  215. The rest of the [literal]#++package-jar++# target goes as follows. As was done
  216. in the JavaDoc compilation, you also need to exclude any test or demo code in
  217. the project here. You need to modify at least the emphasized parts for your
  218. project.
  219. [subs="normal"]
  220. ----
  221. &lt;!-- Include built server-side classes --&gt;
  222. &lt;fileset dir="build/result/classes"&gt;
  223. &lt;patternset&gt;
  224. &lt;include name="**com/example/myaddon/++*++++*++/++*++**"/&gt;
  225. &lt;exclude name="**++*++++*++/client/++*++++*++/++*++**"/&gt;
  226. &lt;exclude name="**++*++++*++/demo/++*++++*++/++*++**"/&gt;
  227. &lt;exclude name="**++*++++*++/test/++*++++*++/++*++**"/&gt;
  228. &lt;exclude name="**++*++++*++/MyDemoUI++*++**"/&gt;
  229. &lt;/patternset&gt;
  230. &lt;/fileset&gt;
  231. &lt;!-- Include widget set sources --&gt;
  232. &lt;fileset dir="src"&gt;
  233. &lt;patternset&gt;
  234. &lt;include name="**com/exaple/myaddon/++*++++*++/++*++**"/&gt;
  235. &lt;/patternset&gt;
  236. &lt;/fileset&gt;
  237. &lt;!-- Include JavaDoc in the JAR --&gt;
  238. &lt;fileset dir="${result-dir}/javadoc"
  239. includes="**/*"/&gt;
  240. &lt;/jar&gt;
  241. &lt;/target&gt;
  242. ----
  243. You should now be ready to run the build script with Ant.
  244. endif::web[]
  245. (((range="endofrange", startref="term.gwt.addons")))