Bloggers recientes

Fady Hakim

Staff
9 Mensajes
19 de mayo de 2018

Jamie Sammons

Staff
15 Mensajes
18 de mayo de 2018

Kyle Joseph Stiemann

Staff
12 Mensajes
15 de mayo de 2018

Alexander Valencia

Staff
1 Mensajes
14 de mayo de 2018

Neha Goyal

20 Mensajes
11 de mayo de 2018

Daniel Tyger

6 Mensajes
7 de mayo de 2018

David H Nebinger

78 Mensajes
4 de mayo de 2018

Yanan Yuan

Staff
6 Mensajes
17 de abril de 2018

Dennis Ju

Staff
3 Mensajes
16 de abril de 2018

Yasuyuki Takeo

Staff
3 Mensajes
11 de abril de 2018
« Atrás

Liferay SDK shared plugins

Company Blogs 15 de marzo de 2013 Por Igor Beslic Staff

 

Hi all, I want to share with you something that is pretty cool for me and I found it super useful. It is shared type of Liferay SDK plugin we use to generate jar entry that can be referred by your other plugins as its library entry.

To show how shared plugin is useful lets just mention that liferay-plugin-package.properties already supports some widely used dependency declarations:

  1. dependency to Liferay Portal jars can be declared using
    • portal-dependency-jars - during compile phase it will use portal-dependency.jar but it will be excluded from created archive
    • portal-dependency-tlds
  2. dependency to other plugins auto-generated *-service.jar entry you declare using:
    • required-deployment-contexts - during compile phase it will fetch required-deployment-context-service.jar and include it in created archive

Why shared plugin?

Once in your life, your system design will assume more than one interdependent plugin (and even simple Liferay integration cases can't avoid it). Your team will end up with common code used in each plugin such are various utilities and own APIs. Good starting point for refactoring it is creation of shared type of plugin, extracting common code to it and declaring dependency to it in all other plugins code was used. I'll demonstrate it using always funny batman plugin invented by my coleague Igor:
  • Once you're inside your SDK go to shared folder and create structure for your new plugin:
mkdir batman-shared
cd to batman-shared
  • Create ant build file (you can copy an existing from other plugin):
vim build.xml
adopt it to suite your shared plugin:
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="batman-shared" basedir="." default="deploy">
 <property name="plugin.version" value="1" />
 <import file="../build-common-shared.xml" />
</project>
  • Configure project files

mkdir src

mkdir lib (this is optional if your code doesn't need any additional jar file)

ant setup-eclipse

  • Put your packages and classes into src folder
ant jar
 
In this point you have plain java project and you can continue developing it.
 

How to refer shared plugin from other plugin?

Let say we have batman-portlet plugin. To refer batman-shared we need to update batman-portlet plugin build.xml with new line:
<property name="import.shared" value="batman-shared" />
If you have more than one shared plugin you can refer all of them:
<property name="import.shared" value="batman-shared,robin-shared" />
 
If ant compile was issued from batman-portlet plugin batman-shared.jar will be created and placed into plugins lib folder. Also it will be included in generated archive file.
Note if your shared plugin use own lib to declare additional jars, all those jars will be copied also. So if you care about your final product size be aware of these details.
 
Hope this will help you organise your code better - it helped us.
Respuestas anidadas Autor Fecha
Hi Igor, In which version of the SDK is this... Pep A 18 de abril de 2013 7:18
Liferay SDK 6.1 GA3 Imad T. 12 de noviembre de 2013 6:08
This shared plugins work good when working with... Juan Camilo Carrillo 12 de junio de 2014 15:25
Thanks for sharing this valuable information. ... Firoza Saiyed 19 de agosto de 2015 22:31
nice and helpful . but my query is . for... twinkal N patel 25 de noviembre de 2015 2:03

Hi Igor,

In which version of the SDK is this feature available?

I am not able to find this feature within the Liferay Plugins SDK 6.1 GA 2

Regards
Publicado el día 18/04/13 7:18.
Publicado el día 12/11/13 6:08 en respuesta a Pep A.
This shared plugins work good when working with Java classes, but when trying to work for JSPs in hooks are not working. The cause seems that jsps are only copied to webapps/ROOT and are not running inside the plugin. For hook java classes works fine.
Publicado el día 12/06/14 15:25.
Thanks for sharing this valuable information.

Thanks,
Firoza
Publicado el día 19/08/15 22:31.
nice and helpful . but my query is .
for example i just shared some classes and lib. and used in a hook. so my lib is copied into my hook. so is it copied lib to every plugin in which i used shared plugin ? i mean lib is duplicated or referring one common lib ?
Publicado el día 25/11/15 2:03.