Servlet-based portlets have little overhead and are easy to upgrade. This
tutorial shows you how to upgrade them and 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.
To get the most from this tutorial, you can 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
- 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
- Developed in a Liferay Plugins SDK 6.2
Follow these steps to upgrade a servlet-based portlet:
The Upgrade Planner makes adapting a portlet’s code straightforward, and it automates much of the process.
The sample portlet relied on Liferay Portal to provide several dependency JAR
files. Here’s the
portal-dependency-jars property from the portlet’s
portal-dependency-jars=\ dom4j.jar,\ jabsorb.jar,\ json-java.jar
Instructions for using packages that Liferay DXP exports are found here. Liferay DXP 7.0’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 avoid packages from compile time 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 DXP’s OSGi runtime and is available to users.
Congratulations! You’ve upgraded and deployed your servlet-based portlet to Liferay DXP 7.0.
Migrating Plugins SDK Projects to Workspace and Gradle
Using Dependency Management Tools