Ext Plugin with Liferay 7 in just 5 steps

admin

April 28, 2022

 

The Liferay developer community has been waiting since long for Ext with Liferay 7 and it got recently released with GA4. This post will be focused on Ext Plugin and how to implement Ext Plugin in Liferay 7/ DXP. In case you are new to Liferay and don’t know what is EXT, here is quick background.

What is Ext?

Ext is stand for extension plugin/environment. Ext plugins are most powerful tool used to extend Liferay Portal. The customization which can’t be done using Hook, can be achieved with Ext. Liferay supports the following use cases for Ext plugin.

1. Custom implementation for any beans which declared in Liferay Portal’s Spring files. (Wherever possible use service wrappers instead of an Ext plugin). Liferay 7 removed many beans, so make sure your overriding beans are still relevant.

2. Overwriting a class in Liferay Portal core JAR.

3. Modify Liferay Portal’s web.xml file.
 
Ext plugins are not recommended unless there is no other way to achieve the goal. Ext plugin can only be created using Plugin SDK.

 
Here are some pre-requisites:

 
Let’s look at Ext with Liferay 7 by taking example of how to override any service implementation class using Ext.
 
Here are the steps:

1. First of all create Ext Plugin:

  • To create , Click File menu → New → Liferay Plugin Provide appropriate name for module, select Build type as “Ant(liferay-plugin-sdk)” and Plugin type as “Ext”.
  • If you have not configured Plugin SDK yet click Next and configure Plugin SDK.

 
2. Create ext-spring.xml file:

  • Navigate to ext-impl/src and create META-INF folder and create ext-spring.xml file inside it.

 
3. Defining custom Bean:

  • To override method of any XXXLocalServiceImpl you need to define custom bean definition in ext-spring.xml.
  • You can get bean definition from spring configuration files mentioned in spring.configs property of portal.properties file.
     
    Example, To override method of UserLocalServiceImpl you need to add following bean definition inside beans tag in ext-spring.xml file. UserLocalServiceImpl bean details are available in portal-spring.xml. 

        <bean class=“com.custom.user.CustomUserLocalServiceImpl”         id=“com.liferay.portal.kernel.service.UserLocalService” />
          </ bean>

     

4. Create Custom Implementation class:

  • Create CustomUserLocalServiceImpl class which we have mentioned before in bean definition. It must extends UserLocalServiceImpl.
    Example,

        public class CustomUserLocalServiceImpl extends UserLocalServiceImpl
  • Now you can override any method of UserLocalServiceImpl in CustomUserLocalServiceImpl and there is no need to copy entire code of the original class, just override the method with your business logic.

5. Deployment Steps:

Ext plugin is now ready for deployment. Before we move ahead make sure “app.server.dir” property is configured in build.[username].properties file.

  • Deploying plugin using IDE:
  • Using Ant tasks available in IDE you need to use “deploy” or “direct-deploy” to deploy your Ext plugin
  • Or drag Ext plugin from Project explorer onto server you configured in IDE. IDE automatically restart server to detect and publish Ext plugin.
    The direct-deploy task will target all changes directly to the appropriate folder in Liferay Portal. The deploy task will generate .war file with all your changes in it and then deploys it to your Liferay Portal.
  • Build Successful message indicates that your plugin is being deployed. Liferay Portal console should show a message like this:

        Extension environment for [your project]-ext has been applied. You must reboot the server and redeploy all other plugins.
  • Now restart portal instance so that it will detect and publish the Ext plugin.

Congratulations, you are done with Ext plugin. I hope this post will help you for customization with Liferay Portal.

 

Post by,

Zeenesh Patel

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments