Friday, May 4, 2012

Access Liferay Service & Util and Custom Portlet Service & Util Class in Velocity Template

Here are the steps to access services and util class of custom portlet in velocity template.

1) Make sure the services and util class which you want to access are available inside tomcat/lib/ext.

2) In order to access services you need to place below property inside portal-ext.

By default this property will be like this

Which means you wont be able to access serviceLocator inside velocity template.
So make sure before you access any service inside velocity template change this

3) Access services using findService Method of Custom Portlet in Velocity.

Normally we use findService(serviceName) method to access Liferay service.
But to access custom portlet service we have to use findService(contextName,ServiceName).

findService(serviceName) will search at the portal level and findService(servletContextName , serviceName) will search at specified portlet level.

4) Access Liferay Services using findService Method in Velocity

5) Access util class using  findUtil Method for inbuilt Util of Liferay

6) Access util Class of Custom Portlet in Velocity refer below link


  1. In Liferay Portal 6.2, we enable accessing services in using this line of code:


    I spent several hours to recognize this change.

    1. Hello all, i want to call a java method in a velocity code, i found your post about service Locator but i don't understand how to adapt my code in order to call my methode. Could you please help me!

      Thank you in advance.

    2. Hi Amit,

      I have tried the access the java class of a portlet from theme as followed by the above step, but still i can't access anything from the java class of portlet. But the above example is working fine with hook, not working with portlet only. Can u please tell me about the problem behind that.


nRelate Posts Only