Legacy Knowledge Base
Published Jul. 2, 2025

Adding to the web.xml With Ext Plugins

Written By

Liferay Support

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

While we make every effort to ensure this Knowledge Base is accurate, itmay not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with anyfeedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

Before using any information from this article, independently verify itssuitability for your situation and project.

A supported use case for using Ext Plugins in Liferay DXP is adding additional functionality to Liferay Digital Enterprise's web.xml file. Before beginning, make sure you've reviewed the generalized Customization with Ext Plugins tutorial.

Resolution

As an example, you'll create a sample Ext plugin that adds to your Liferay Digital Enterprise's existing web.xml file (e.g., in the /tomcat-[version]/webapps/ROOT/WEB-INF folder). You'll add a new printout in the console during Liferay Digital Enterprise's startup.

  1. Navigate into your Plugins SDK's /ext folder and run the following command:

    create.[bat|sh]  add-printout "Add Printout"
    

    Your Ext plugin is generated and now resides in the Plugins SDK's /ext folder with the name you assigned followed by -ext (e.g., add-printout-ext).

  2. For your Liferay Digital Enterprise installation to recognize new functionality in the web.xml, you must create a class that implements the ServletContextListener interface. This class will initialize a servlet context event for which you'll add your new functionality. In the /docroot/WEB-INF/ext-impl/src folder, create the folder structure representing the package name you want your new class to reside in (e.g., com/liferay/portal/servlet/context). Then create your new Java class:

    package com.liferay.portal.servlet.context;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    public class ExtAddEntryWebXmlPortalContextLoaderListener
            implements ServletContextListener {
    public void contextDestroyed(ServletContextEvent servletContextEvent) { } public void contextInitialized(ServletContextEvent servletContextEvent) { System.out.println("EXT_ADD_ENTRY_WEBXML_INSTALLED_SUCCESSFULLY"); } 

    The above class includes two methods that initialize and destroy your servlet context event. Be sure to add the new web.xml's functionality when the portal context is initializing. To add a printout verifying the Ext plugins installation, a simple print statement was defined in the contextInitialized(...) method:

    System.out.println("EXT_ADD_ENTRY_WEBXML_INSTALLED_SUCCESSFULLY");
    
  3. Now that you've defined a servlet context event, you should add a listener to your web.xml that listens for it. In the docroot/WEB-INF/ext-web/docroot/WEB-INF folder, open the web.xml file, which was generated for you by default.

  4. Add the following tag between the tags:

    <listener>
        <listener-class>com.liferay.portal.servlet.context.ExtAddEntryWebXmlPortalContextLoaderListener</listener-class>
    </listener>
    

Excellent! Now when your Ext plugin is deployed, your Liferay Digital Enterprise installation will create a ServletContextListener instance, which will initialize a custom servlet context event. This event will be recognized by the web.xml file, which will add the new functionality to your Liferay Digital Enterprise installation. Follow the instructions in the Deploy the Plugin section for help deploying the Ext plugin to your server.

Did this article resolve your issue ?

Legacy Knowledge Base