Thursday, August 4, 2011

How to create portlet using Plugins-SDK and Eclipse

In this article, I’ll teach you to create a portlet as plugin ( portlet plugin is a portlet that will be deployed using separate war file, quite different from ext approach). There are two ways to do this :

  1. Using Liferay’s plugins SDK
  2. Using Eclipse alone.

Let’s start

  1. Using Liferay’s plugins SDK : This approach has some advantages, that Plugins SDK would generate all necessary files(liferay-display.xml,liferay-portlet.xml, portlet.xml, etc) and directory structure for your portlet, so you just need to modify the files to suit your needs. One disadvantage of this approach is, if you want to compile and create WAR using Plugins SDK’s ant task, you have to follow their directory structure, i.e. there should be folder docroot, and html. Of course you can change this if you want to edit the ant task.I won’t describe the steps again, as it’s already described here . If you use Liferay 5.1.2, don’t forget to replace portlet.zip with the one here. Otherwise you’ll have error.
  2. Using Eclipse alone : with this approach, you don’t need to depend on Plugins SDK. You just need to have Eclipse IDE installed, along with WTP (Web Tools Platform) Plugins. You need WTP plugins to import WAR file from sample portlet, modify the files and add your source, and later export it as a WAR file. Here are the steps ( I assume your Eclipse is ready, with WTP installed) :
  • Download sample portlet that you like. ( If you want to create Struts portlet, you can download the sample from here ).
  • Import the WAR file into Eclipse
  • Resolve dependencies. If you use Tomcat as app server, and your Tomcat already installed Liferay portal, you can create user libraries that includes these directories (and jar files inside these directories) : $TOMCAT_HOME/common/lib, $TOMCAT_HOME/common/lib/ext, $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib

Now, you need to edit some configuration files under your $PROJECT/WebContent as follows :

  • liferay-display.xml : You need to modify this file to categorize your portlet under a category.
  • liferay-plugin-package.properties : You need to modify this file to add library dependencies for your portlet. For example, if your portlet depends on displaytag.jar, you don’t need to add displaytag.jar manually to your $PROJECT_HOME/WebContent/WEB-INF/lib. Instead, you just need to add on your liferay-plugin-package.properties like this :
    1portal.dependency.jars=\
    2commons-logging.jar,\
    3displaytag.jar,\
    4commons-logging,\
    5commons-lang,\
    6commons-collections,\
    7commons-beanutils,\
    8log4j.jar



Don’t forget to add your ‘tag library description’ ( tld ) into this file as well, like this

1portal.dependency.tlds=struts-bean.tld,struts-html.tld,struts-logic.tld,struts-tiles.tld,displaytag.tld


For struts portlet, you don’t need to add struts.jar into this file.

  • liferay-plugin-package.xml : To give description about your portlet, i.e. license, liferay version, author, etc.
  • liferay-portlet.xml : liferay-specific portlet description.
  • portlet.xml : ‘deployment descriptor’ of the portlet
  • struts-config.xml, tiles-defs.xml ( If you use struts and tiles ). If you use bean:write tag, don’t forget to add resources to your struts-config.xml, for example like this
    1<message-resources parameter="content.test.Language" />


    Don’t forget to add your language files(Language.properties, Language_en.properties, Language_*.properties) under content.test package below your source folder.

  • web.xml : You don’t need to modify this one, except for special case.

Now you’re ready to program your portlet. You don’t need to depend on Plugins SDK to compile and package your portlet into WAR, since you can do this using Eclipse.

Happy programming !

Source: http://portaldevelopment.wordpress.com/2009/01/06/how-to-create-portlet-using-plugins-sdk-and-eclipse/

http://www.liferay.com/community/forums/-/message_boards/message/6479921

http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+IDE+Installation+Guide

http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+IDE+Getting+Started+Tutorial

http://www.liferay.com/community/wiki/-/wiki/Main/Plugins+SDK

http://www.ibm.com/developerworks/vn/edu/os-ag-portlets/section7.html

No comments:

Router Packet Networking

Đây là video ngắn khá hay, mô tả đường đi của một gói tin trên Mạng Internet.