Why I can’t use portal-impl in my portlet?

When I started my adventure with liferay and I was young I had a big headache with a view: „Why liferay developers didn’t share portal-impl.jar for external portlets. This is so stupid”. When we don’t have access to this module our development is very difficult. I can’t extend my Action class and I must manually attend all incoming requests beacause portal-impl.jar provides most classes used by the portal’s portlets. Why I can’t use this one?

Today, when I spent a long time with liferay my answer is: NO, you should not use a portal-impl.jar in your portlet. Remember: NEVER put portal-impl into anywhere other than where it came from. This will cause untold problems beacause portal-impl is the central core of the portal and it is a main piece of cake. So you can’t put portal-impl in lib directory in your portlets or in other strange places. Why? Liferay uses all kinds of classloader tricks to get access to various classes. So adding portal-impl to library folder in your portlet will realy mess this up. There will be duplicated instances of classes which are load from different class loaders. Additionaly portal-impl.jar contains internal classes of liferay core implementation, so if you use it in this version remember that next one can change all method’s or just remove some classes.

In portal-service.jar liferay provides a set of methods, which you can use in your own implementation. It sits in the global classpath (on tomcat this is <tomcat>/lib/ext/*.jar). All the services and utilities are available from these.

Wait a second… this feature looks nice, but how can I develop my controller (for example struts)? You should use apache struts bridge to handle lifecycle of struts portlet (refer sample-struts-portlet in community svn plugin repository). Also Liferay provides some kinds of bridges (e.g. mvc, php, python and more) and it is the simplest and the best way to create your own action class or your own controller. In my opinion there are some very important reasons to do with this way:

  • your code is totally independent
  • portlets are more flexible
  • there is a big chance that your code will be working with newer version of liferay
  • you write code with framework you like

But Liferay’s StrutsPortlet bridge should not be used for any new development. If you really must use Struts 1.x it’s better to use Apache portlet bridge. You can also use Liferay’s MVCPortlet. Or, you can use one of the other frameworks supported by Liferay: Spring MVC, Struts 2, and JSF.

DOC_22
Advertisements

3 Responses to Why I can’t use portal-impl in my portlet?

  1. Paranormal says:

    hello
    when i try using listing my organization hierarchy i have to use
    classes from portal-impl.jar
    if i deploy my JSF portlet without this jar it throws ClassNotFoundException
    for example if i use this code
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(Organization.class);
    OrganizationLocalServiceUtil.dynamicQuery(query);
    it throws
    OrganizationModel not found
    or something like this
    so i had to put the portal-impl.jar in my portlet lib
    ant it worked fine

    regard

    • Piotr Filipowicz says:

      Hi! Thx for the comment. Your description is example how we shouldn’t do it. Having more than one portal-iml.jar in the application server will
      wreak havoc on your installation. Since portal-impl.jar is only for Liferay core, you should not see this jar in your portlet.

  2. sarika says:

    11:09:50,837 INFO [AutoDeployDir:167] Processing abcd-portlet-6.0.6.1.war
    11:09:50,837 INFO [PortletAutoDeployListener:71] Copying portlets for D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war
    Expanding: D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war into D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837\WEB-INF
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837\WEB-INF
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837\META-INF
    Warning: WEB-INF\liferay-plugin-package.properties modified in the future.
    Warning: WEB-INF\tld\liferay-portlet-ext.tld modified in the future.
    Warning: WEB-INF\tld\liferay-portlet.tld modified in the future.
    Warning: WEB-INF\tld\liferay-security.tld modified in the future.
    Warning: WEB-INF\tld\liferay-theme.tld modified in the future.
    Warning: WEB-INF\tld\liferay-ui.tld modified in the future.
    Warning: WEB-INF\tld\liferay-util.tld modified in the future.
    Warning: view.jsp modified in the future.
    Copying 24 files to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\abcd-portlet
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\abcd-portlet
    Deleting directory D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119110950837
    11:09:51,946 INFO [PortletAutoDeployListener:81] Portlets for D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war copied successfully. Deployment will start in a few seconds.
    Jan 19, 2012 11:10:01 AM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deploying web application directory abcd-portlet
    11:10:01,336 INFO [PortletHotDeployListener:220] Registering portlets for abcd-portlet
    11:10:01,539 INFO [PortletHotDeployListener:369] 1 portlet for abcd-portlet is available for use
    11:12:58,532 INFO [AutoDeployDir:167] Processing abcd-portlet-6.0.6.1.war
    11:12:58,532 INFO [PortletAutoDeployListener:71] Copying portlets for D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war
    Expanding: D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war into D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532\WEB-INF
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532\META-INF
    Warning: META-INF\MANIFEST.MF modified in the future.
    Warning: WEB-INF\liferay-plugin-package.properties modified in the future.
    Warning: WEB-INF\tld\liferay-portlet-ext.tld modified in the future.
    Warning: WEB-INF\tld\liferay-portlet.tld modified in the future.
    Warning: WEB-INF\tld\liferay-security.tld modified in the future.
    Warning: WEB-INF\tld\liferay-theme.tld modified in the future.
    Warning: WEB-INF\tld\liferay-ui.tld modified in the future.
    Warning: WEB-INF\tld\liferay-util.tld modified in the future.
    Warning: view.jsp modified in the future.
    Warning: WEB-INF\src modified in the future.
    Copying 15 files to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\abcd-portlet
    Copied 9 empty directories to 1 empty directory under D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\abcd-portlet
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\abcd-portlet
    Deleting directory D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111258532
    11:12:59,500 INFO [PortletAutoDeployListener:81] Portlets for D:\Montage\liferay-portal-6.0.6\deploy\abcd-portlet-6.0.6.1.war copied successfully. Deployment will start in a few seconds.
    Jan 19, 2012 11:13:01 AM org.apache.catalina.startup.HostConfig checkResources
    INFO: Reloading context [/abcd-portlet]
    11:13:01,953 WARN [PluginPackageUtil:1186] Unable to reindex unistalled package abcd-portlet: Unable to communicate with repository http://plugins.liferay.com/official
    11:13:01,953 INFO [ExtHotDeployListener:205] Extension environment for abcd-portlet will not be undeployed
    11:13:01,953 INFO [PortletHotDeployListener:404] Unregistering portlets for abcd-portlet
    11:13:02,063 INFO [PortletHotDeployListener:435] 1 portlet for abcd-portlet was unregistered
    11:13:02,313 INFO [PortletHotDeployListener:220] Registering portlets for abcd-portlet
    11:13:02,406 INFO [PortletHotDeployListener:369] 1 portlet for abcd-portlet is available for use
    11:19:10,502 INFO [AutoDeployDir:167] Processing test123-portlet-6.0.6.1.war
    11:19:10,502 INFO [PortletAutoDeployListener:71] Copying portlets for D:\Montage\liferay-portal-6.0.6\deploy\test123-portlet-6.0.6.1.war
    Expanding: D:\Montage\liferay-portal-6.0.6\deploy\test123-portlet-6.0.6.1.war into D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518\WEB-INF
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518\WEB-INF\classes
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518\META-INF
    Warning: WEB-INF\classes\com\test\Test123.class modified in the future.
    Warning: WEB-INF\src\com\test\Test123.java modified in the future.
    Warning: WEB-INF\classes\com modified in the future.
    Warning: WEB-INF\src modified in the future.
    Warning: WEB-INF\src\com modified in the future.
    Warning: WEB-INF\src\com\test modified in the future.
    Copying 13 files to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\test123-portlet
    Copying 1 file to D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\webapps\test123-portlet
    Deleting directory D:\Montage\liferay-portal-6.0.6\tomcat-6.0.29\temp\20120119111910518
    11:19:11,549 INFO [PortletAutoDeployListener:81] Portlets for D:\Montage\liferay-portal-6.0.6\deploy\test123-portlet-6.0.6.1.war copied successfully. Deployment will start in a few seconds.
    Jan 19, 2012 11:19:12 AM org.apache.catalina.startup.HostConfig checkResources

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: