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.

portal-liferay.asciidoc 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ---
  2. title: Developing Vaadin Portlets for Liferay
  3. order: 4
  4. layout: page
  5. ---
  6. [[portal.liferay]]
  7. = Developing Vaadin Portlets for Liferay
  8. A Vaadin portlet requires resources such as the server-side Vaadin libraries, a
  9. theme, and a widget set. You have three basic ways to deploy these: either
  10. globally in Liferay so that the resources are shared between all Vaadin
  11. portlets, as self-contained WARs where each portlet carries their own
  12. resources or as OSGi bundles in Liferay 7.
  13. For Liferay 7 and OSGi portlets, see <<portal-osgi#portal.osgi,"OSGi Portlets on Liferay 7">>. This is the recommended approach when using Vaadin 8.1 or later and Liferay 7.
  14. Currently, the latest Maven archetype supports the OSGi approach.
  15. The material below applies mostly to non-OSGi portlets.
  16. == Developing Vaadin Portlets for Liferay 6.2
  17. In non-OSGi environments, the self-contained approach to static resources is
  18. easier and more flexible, as the different portlets may have different
  19. versions of the resources.
  20. Using shared resources is not recommended as it forces all portlets on a page
  21. to use the same Vaadin version and resources. If using this approach, you can
  22. install the shared resources as described in <<portal.liferay.install>>.
  23. At the time of writing, the latest Liferay release 6.2 is bundled with a version
  24. of Vaadin release 6. If you want to use Vaadin 8 portlets with shared resources,
  25. you first need to remove the old ones as described in <<portal.liferay.remove>>.
  26. [[portal.liferay.profile]]
  27. == Defining Liferay Profile for Maven
  28. When creating a Liferay portlet project with a Maven archetype or the Liferay
  29. IDE, you need to define a Liferay profile. With the Liferay IDE, you can create
  30. it when you create the project, as described in <<portal.liferay.ide>>, but for
  31. creating a project from the Maven archetype, you need to define in manually.
  32. [[portal.liferay.profile.settings]]
  33. === Defining Profile in [filename]#settings.xml#
  34. Liferay profile can be defined either in the user or in the global
  35. [filename]#settings.xml# file for Maven. The global settings file is located in
  36. [filename]#${MAVEN_HOME}/conf/settings.xml# and the user settings file in
  37. [filename]#${USER_HOME}/.m2/settings.xml#. To create a user settings file, copy
  38. at least the relevant headers and root element from the global settings file.
  39. [subs="normal"]
  40. ----
  41. ...
  42. &lt;profile&gt;
  43. &lt;id&gt;**liferay**&lt;/id&gt;
  44. &lt;properties&gt;
  45. &lt;liferayinstall&gt;**/opt/liferay-portal-6.2-ce-ga2**
  46. &lt;/liferayinstall&gt;
  47. &lt;plugin.type&gt;portlet&lt;/plugin.type&gt;
  48. &lt;liferay.version&gt;**6.2.1**&lt;/liferay.version&gt;
  49. &lt;liferay.maven.plugin.version&gt;**6.2.1**
  50. &lt;/liferay.maven.plugin.version&gt;
  51. &lt;liferay.auto.deploy.dir&gt;${liferayinstall}/**deploy**
  52. &lt;/liferay.auto.deploy.dir&gt;
  53. &lt;!-- Application server version - here for Tomcat --&gt;
  54. &lt;liferay.tomcat.version&gt;**7.0.42**&lt;/liferay.tomcat.version&gt;
  55. &lt;liferay.tomcat.dir&gt;
  56. ${liferayinstall}/tomcat-${liferay.tomcat.version}
  57. &lt;/liferay.tomcat.dir&gt;
  58. &lt;liferay.app.server.deploy.dir&gt;**${liferay.tomcat.dir}/webapps**
  59. &lt;/liferay.app.server.deploy.dir&gt;
  60. &lt;liferay.app.server.lib.global.dir&gt;**${liferay.tomcat.dir}/lib/ext**
  61. &lt;/liferay.app.server.lib.global.dir&gt;
  62. &lt;liferay.app.server.portal.dir&gt;**${liferay.tomcat.dir}/webapps/ROOT**
  63. &lt;/liferay.app.server.portal.dir&gt;
  64. &lt;/properties&gt;
  65. &lt;/profile&gt;
  66. ----
  67. The parameters are as follows:
  68. liferayinstall:: Full (absolute) path to the Liferay installation directory.
  69. liferay.version:: Liferay version by the Maven version numbering scheme. The first two (major and minor) numbers are same as in the installation package. The third (maintenance) number starts from 0 with first GA (general availability) release.
  70. liferay.maven.plugin.version:: This is usually the same as the Liferay version.
  71. liferay.auto.deploy.dir:: The Liferay auto-deployment directory. It is by default [filename]#deploy# under the Liferay installation path.
  72. liferay.tomcat.version(optional):: If using Tomcat, its version number.
  73. liferay.tomcat.dir:: Full (absolute) path to Tomcat installation directory. For Tomcat bundled with Liferay, this is under the Liferay installation directory.
  74. liferay.app.server.deploy.dir:: Directory where portlets are deployed in the application server used for Liferay. This depends on the server - for Tomcat it is the [filename]#webapps# directory under the Tomcat installation directory.
  75. liferay.app.server.lib.global.dir:: Library path where libraries globally accessible in the application server should be installed.
  76. liferay.app.server.portal.dir:: Deployment directory for static resources served by the application server, under the root path of the server.
  77. If you modify the settings after the project is created, you need to touch the
  78. POM file in the project to have the settings reloaded.
  79. [[portal.liferay.profile.properties]]
  80. === Activating the Maven Profile
  81. The Maven 2 Plugin for Eclipse (m2e) must know which Maven profiles you use in a
  82. project. This is configured in the [menuchoice]#Maven# section of the project
  83. properties. In the [guilabel]#Active Maven Profiles# field, enter the profile ID
  84. defined in the [filename]#settings.xml# file, as illustrated in
  85. <<figure.portal.liferay.profile.properties>>.
  86. [[figure.portal.liferay.profile.properties]]
  87. .Activating Maven Liferay Profile
  88. image::img/liferay-maven-profile.png[]
  89. [[portal.liferay.project]]
  90. == Creating a Portlet Project with Maven
  91. Creation of Vaadin a Maven project is described in
  92. <<../getting-started/getting-started-maven#getting-started.maven,"Using
  93. Vaadin with Maven">>. For a Liferay project, you should use the
  94. [literal]#++vaadin-archetype-liferay-portlet++#.
  95. Note: For creating Liferay 6.2 projects for Vaadin Framework 8.1, use the 8.0
  96. version of the archetype and then update the dependency versions for Vaadin
  97. Framework.
  98. [[portal.liferay.project.archetype-parameters]]
  99. === Archetype Parameters
  100. The archetype has a number of parameters. If you use Maven Plugin for Eclipse
  101. (m2e) to create the project, you get to enter the parameters after selecting the
  102. archetype, as shown in <<figure.portal.liferay.project.archetype-parameters>>.
  103. Minimally, you just need to enter the artifact ID. To activate the Maven profile
  104. created as described earlier in <<portal.liferay.profile>>, you need to specify
  105. the profile in the [guilabel]#Profiles# field under the [guilabel]#Advanced#
  106. section.
  107. [[figure.portal.liferay.project.archetype-parameters]]
  108. .Liferay Project Archetype Parameters
  109. image::img/liferay-maven-project.png[]
  110. The other parameters are the following:
  111. vaadinVersion:: Vaadin release version for the Maven dependency.
  112. uiClassName:: Class name of the UI class stub to be created.
  113. theme:: Theme to use. You can use either a project theme, which must be compiled before deployment, or use one of the default themes.
  114. portletTitle:: Title shown in the portlet title bar.
  115. portletShortTitle:: Title shown in contexts where a shorter title is preferred.
  116. portletKeywords:: Keywords for finding the portlet in Liferay.
  117. portletDescription:: A description of the portlet.
  118. portletName:: Identifier for the portlet, used for identifying it in the configuration files.
  119. portletDisplayName:: Name of the portlet for contexts where it is displayed.
  120. [[portal.liferay.ide]]
  121. == Creating a Portlet Project in Liferay IDE
  122. Liferay IDE, which you install in Eclipse as plugins just like the Vaadin
  123. plugin, enables a development environment for Liferay portlets. Liferay IDE
  124. allows integrated deployment of portlets to Liferay, just like you would deploy
  125. servlets to a server in Eclipse. The project creation wizard supports creation
  126. of Vaadin portlets.
  127. Loading widget sets, themes, and the Vaadin JAR from a portlet is possible as
  128. long as you have a single portlet, but causes a problem if you have multiple
  129. portlets. To solve this, Vaadin portlets need to use a globally installed widget
  130. set, theme, and Vaadin libraries.
  131. __Liferay 6.2 comes bundled with an older Vaadin 6 version. If you want to use
  132. Vaadin 8, you need to remove the bundled version and install the newer one
  133. manually as described in this chapter.__
  134. In these instructions, we assume that you use Liferay bundled with Apache
  135. Tomcat, although you can use almost any other application server with Liferay
  136. just as well. The Tomcat installation is included in the Liferay installation
  137. package, under the [filename]#tomcat-x.x.x# directory.
  138. [[portal.liferay.remove]]
  139. == Removing the Bundled Installation
  140. Before installing a new Vaadin version, you need to remove the version bundled
  141. with Liferay. You need to remove the Vaadin library JAR from the library
  142. directory of the portal and the [filename]#VAADIN# directory from under the root
  143. context. For example, with Liferay bundled with Tomcat, they are usually located
  144. as follows:
  145. * [filename]#tomcat-x.x.x/webapps/ROOT/html/VAADIN#
  146. * [filename]#tomcat-x.x.x/webapps/ROOT/WEB-INF/lib/vaadin.jar#
  147. [[portal.liferay.install]]
  148. == Installing Vaadin Resources
  149. To use common resources needed by multiple Vaadin portlets, you can install them
  150. globally as shared resources as described in the following.
  151. If you are installing Vaadin in a Liferay version that comes bundled with an
  152. older version of Vaadin, you first need to remove the resources as described in
  153. <<portal.liferay.remove>>.
  154. In the following, we assume that you use only the built-in "reindeer" theme in
  155. Vaadin and the default widget set.
  156. . Get the Vaadin installation package from the Vaadin download page
  157. . Extract the following Vaadin JARs from the installation package: [filename]#vaadin-server.jar# and [filename]#vaadin-shared.jar#, as well as the [filename]#vaadin-shared-deps.jar# and [filename]#jsoup.jar# dependencies from the [filename]#lib# folder
  158. . Rename the JAR files as they were listed above, without the version number
  159. . Put the libraries in [filename]#tomcat-x.x.x/webapps/ROOT/WEB-INF/lib/#
  160. . Extract the [filename]#VAADIN# folders from [filename]#vaadin-server.jar#,
  161. [filename]#vaadin-themes.jar#, and [filename]#vaadin-client-compiled.jar# and
  162. copy their contents to [filename]#tomcat-x.x.x/webapps/ROOT/html/VAADIN#.
  163. +
  164. [subs="normal"]
  165. ----
  166. [prompt]#$# [command]#cd# tomcat-x.x.x/webapps/ROOT/html
  167. ----
  168. +
  169. [subs="normal"]
  170. ----
  171. [prompt]#$# [command]#unzip# path-to/vaadin-server-8.1.0.jar 'VAADIN/*'
  172. ----
  173. +
  174. [subs="normal"]
  175. ----
  176. [prompt]#$# [command]#unzip# path-to/vaadin-themes-8.1.0.jar 'VAADIN/*'
  177. ----
  178. +
  179. [subs="normal"]
  180. ----
  181. [prompt]#$# [command]#unzip# path-to/vaadin-client-compiled-8.1.0.jar 'VAADIN/*'
  182. ----
  183. You need to define the widget set, the theme, and the JAR in the
  184. [filename]#portal-ext.properties# configuration file for Liferay, as described
  185. earlier. The file should normally be placed in the Liferay installation
  186. directory. See Liferay documentation for details on the configuration file.
  187. Below is an example of a [filename]#portal-ext.properties# file:
  188. ----
  189. # Path under which the VAADIN directory is located.
  190. # (/html is the default so it is not needed.)
  191. # vaadin.resources.path=/html
  192. # Portal-wide widget set
  193. vaadin.widgetset=com.vaadin.server.DefaultWidgetSet
  194. # Theme to use
  195. # This is the default theme if nothing is specified
  196. vaadin.theme=valo
  197. ----
  198. The allowed parameters are:
  199. [parameter]#vaadin.resources.path#:: Specifies the resource root path under the portal context. This is
  200. [filename]#/html# by default. Its actual location depends on the portal and the
  201. application server; in Liferay with Tomcat it would be located at
  202. [filename]#webapps/ROOT/html# under the Tomcat installation directory.
  203. [parameter]#vaadin.widgetset#:: The widget set class to use. Give the full path to the class name in the dot
  204. notation. If the parameter is not given, the default widget set is used.
  205. [parameter]#vaadin.theme#:: Name of the theme to use. If the parameter is not given, the default theme is
  206. used, which is [literal]#++valo++#.
  207. You will need to restart Liferay after creating or modifying the
  208. [filename]#portal-ext.properties# file.