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-osgi.asciidoc 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ---
  2. title: OSGi Portlets on Liferay 7
  3. order: 3
  4. layout: page
  5. ---
  6. [[portal.osgi]]
  7. = OSGi Portlets on Liferay 7
  8. Lifeary 7 supports modular portlet development using OSGi, and enables e.g.
  9. using multiple different Vaadin versions in different portlets on a page.
  10. For general OSGi considerations with Vaadin Framework such as packaging and
  11. bundle manifests, and how to publish static resources such as themes and
  12. widget sets, see
  13. <<../advanced/advanced-osgi#advanced.osgi,"Vaadin OSGi Support">>.
  14. [[portal.osgi.portlet]]
  15. == Publishing a Portlet With OSGi
  16. Publishing an OSGi portlet on Liferay 7+ can be done in two ways: using
  17. annotations or using properties.
  18. Annotating a UI class with [interfacename]#@VaadinLiferayPortletConfiguration#
  19. (available in `vaadin-liferay-integration`) and making it an OSGi service of type
  20. [classname]#UI# is the easiest way to automatically publish the UI as a portlet
  21. and configure it to use the correct static resources.
  22. [source, java]
  23. ----
  24. @Theme(MyTheme.THEME_NAME)
  25. @VaadinLiferayPortletConfiguration(name = "Vaadin.Tutorial.1", displayName = "Vaadin Tutorial App")
  26. @Component(service = UI.class, scope = ServiceScope.PROTOTYPE)
  27. public class MyUI extends UI {
  28. ...
  29. }
  30. ----
  31. When using this approach, it is not necessary to create all the portlet
  32. property files that plain JSR-362 portlets require.
  33. Alternatively, the property [literal]#com.vaadin.osgi.liferay.portlet-ui=true#
  34. can be used when publishing a UI as an OSGi service to publish the UI as a portlet.
  35. The scope of the service should be set to [literal]#ServiceScope.PROTOTYPE#, as new instances
  36. of the UI will be needed. When this scope set, declarative services annotations can
  37. be used to get references to other services within a UI instance.
  38. This is not an absolute requirement if you are not using other declarative services
  39. annotations in your UI besides the [interfacename]#@Component#. If the scope is not
  40. set to prototype a warning will be logged and the constructor of the UI will be used
  41. when new instances are needed.
  42. [source, java]
  43. ----
  44. @Theme(MyTheme.THEME_NAME)
  45. @Component(service = UI.class, property = {
  46. "com.liferay.portlet.display-category=category.vaadin",
  47. "javax.portlet.name=my.vaadin.app.app.1.0.0",
  48. "javax.portlet.display-name=Tutorial Portlet",
  49. "javax.portlet.security-role-ref=power-user,user",
  50. "com.vaadin.osgi.liferay.portlet-ui=true"},
  51. scope = ServiceScope.PROTOTYPE)
  52. public class MyUI extends UI {
  53. ...
  54. }
  55. ----
  56. [[portal.osgi.portlet.gradle]]
  57. == Deployment a Portlet With OSGi (Gradle)
  58. Here is an example of a Liferay workspace with a portlet module and a short readme on how to deploy that to a Liferay portal.
  59. link:https://github.com/elmot/liferay-7-solid-portlet-example/[]
  60. [[portal.osgi.portlet]]
  61. == Deployment a Portlet With OSGi (Maven)
  62. An OSGi portlet should be packaged as a JAR with a proper OSGi bundle
  63. manifest, and deployed to a portal that has its required bundles installed.
  64. The maven archetype `com.vaadin:vaadin-archetype-liferay-portlet` is a good starting point to build an OSGi portlet application.
  65. The required bundles (and the application as well) can be installed using link:https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/blade-cli[blade client].
  66. The latest client binary can be downloaded from the link: link:https://releases.liferay.com/tools/blade-cli/latest/blade.jar[]
  67. Here is an example script for doing that (be sure to check the versions required by your project using *mvn dependency:list* ):
  68. [source, shell]
  69. ----
  70. java -jar blade.jar sh start https://repo1.maven.org/maven2/org/jsoup/jsoup/1.11.2/jsoup-1.11.2.jar
  71. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/external/gentyref/1.2.0.vaadin1/gentyref-1.2.0.vaadin1.jar
  72. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-shared/8.6.3/vaadin-shared-8.6.3.jar
  73. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-server/8.6.3/vaadin-server-8.6.3.jar
  74. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-osgi-integration/8.6.3/vaadin-osgi-integration-8.6.3.jar
  75. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-client-compiled/8.6.3/vaadin-client-compiled-8.6.3.jar
  76. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-themes/8.6.3/vaadin-themes-8.6.3.jar
  77. java -jar blade.jar sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-liferay-integration/8.6.3/vaadin-liferay-integration-8.6.3.jar
  78. java -jar blade.jar sh start file:<path_to_liferay_portlet.jar>
  79. ----
  80. However if you are using Vaadin 8 with compatibility libraries, the list above does not work, since you need to load compatibility versions of the bundles in addition to base versions in right order, here is example of that
  81. [source, shell]
  82. ----
  83. blade sh start https://repo1.maven.org/maven2/org/jsoup/jsoup/1.11.3/jsoup-1.11.3.jar
  84. blade sh start https://repo1.maven.org/maven2/com/vaadin/external/gentyref/1.2.0.vaadin1/gentyref-1.2.0.vaadin1.jar
  85. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-shared/8.6.4/vaadin-shared-8.6.4.jar
  86. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-compatibility-shared/8.6.4/vaadin-compatibility-shared-8.6.4.jar
  87. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-server/8.6.4/vaadin-server-8.6.4.jar
  88. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-compatibility-server/8.6.4/vaadin-compatibility-server-8.6.4.jar
  89. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-osgi-integration/8.6.4/vaadin-osgi-integration-8.6.4.jar
  90. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-compatibility-client-compiled/8.6.4/vaadin-compatibility-client-compiled-8.6.4.jar
  91. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-compatibility-themes/8.6.4/vaadin-compatibility-themes-8.6.4.jar
  92. blade sh start https://repo1.maven.org/maven2/com/vaadin/vaadin-liferay-integration/8.6.4/vaadin-liferay-integration-8.6.4.jar
  93. java -jar blade.jar sh start file:<path_to_liferay_portlet.jar>
  94. ----