Upgrading a Servlet-based Portlet

This tutorial shows you how to upgrade servlet-based portlets. It refers to code from before and after upgrading a sample servlet-based portlet called Sample JSON (project sample-json-portlet). The portlet shows a Click me link. When users click the link, the Liferay logo appears.

Figure 1: The Sample JSON portlet displays text stating Click me that you can click to initiate an action.

Figure 1: The Sample JSON portlet displays text stating *Click me* that you can click to initiate an action.

To get the most from this tutorial, download and refer to the original sample portlet source code and the upgraded source code.

Here are the sample portlet’s characteristics:

  • Processes requests using a servlet that extends javax.servlet.HttpServlet
  • View layer implemented by JSPs
  • Processes data using JSON objects
  • Relies on manual dependency management
  • Depends on third-party libraries that Liferay Portal 6.2 provides
  • Embeds additional dependencies in its WEB-INF/lib folder
  • Developed in a Liferay Plugins SDK 6.2

To upgrade a servlet-base Portlet, adapt your code to Liferay DXP 7.1’s API using the Liferay Upgrade Planner. When you ran the planner’s Fix Upgrade Problems step, many of the existing issues were autocorrected or flagged. For any remaining errors, consult the Resolving a Plugin’s Dependencies article.

Liferay’s Upgrade Planner identifies code affected by the new API, explains the API changes and how to adapt to them, and in many cases, provides options for adapting the code automatically.

The sample portlet relied on Liferay Portal to provide several dependency JAR files. Here’s the portal-dependency-jars property from the portlet’s liferay-plugin-package.properties file:


Instructions for using packages that Liferay DXP exports are found here. Liferay DXP 7.1’s core system exports the package this portlet needs from each of the above dependency JARs.

The upgraded sample portlet continues to specify these JARs in the portal-dependency-jars property. They’re made available to the portlet at compile time. But to keep compile time packages from conflicting with the core system’s exported packages, the Liferay Plugins SDK 7.0 excludes the JARs from the plugin WAR.

Next, deploy your portlet as you always have.

The server prints messages that indicate the following portlet status:

  • WAR processing
  • WAB startup
  • Availability to users

The portlet is installed to Liferay’s OSGi runtime and is available to users.

Figure 2: Clicking on the sample portlets Click me link shows the Liferay logo.

Figure 2: Clicking on the sample portlet's *Click me* link shows the Liferay logo.

Congratulations! You’ve upgraded and deployed your servlet-based portlet to Liferay DXP 7.1.

Related Topics

Migrating Plugins SDK Projects to Workspace and Gradle

Using Dependency Management Tools

Using the WAB Generator

Migrating Data Upgrade Processes

« Upgrading a Liferay JSF PortletUpgrading a Spring MVC portlet »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0