How to create an external application JAR file and invoke it using a JSP component
Applies to
HCL Digital Experience v9.5 and higher
Introduction
Custom Java logic can be packaged externally into a JAR file and called directly from within Web Content Manager (WCM) components to extend portal capabilities. This article describes how to create an external application JAR file and invoke a custom Java class using a WCM JSP component.
Instructions
DISCLAIMER OF WARRANTIES
The following code is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the code is with you. Should the code prove defective, you assume the cost of all necessary servicing, repair or correction.
-
Create a Java project in Rational Application Developer (RAD) containing a package named
simplesystemoutand a class namedjdrprint. -
Add the following code to the
jdrprintclass:package simplesystemout; public class jdrprint { public static void PrintToSystemout() { System.out.println("JDRPrintClass"); } } -
Export the project as a JAR file and copy it to
<PortalServer_root>/shared/app. -
Create a WCM JSP component at
/jsp/html/JDRPrint.jspwith the following code toJDRPrint.jsp:<%@ page import="com.ibm.workplace.wcm.api.*"%> <%@ page import="com.ibm.workplace.wcm.api.exceptions.*"%> <%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*"%> <% out.print("Running JSP"); simplesystemout.jdrprint.PrintToSystemout(); %> -
Copy
JDRPrint.jsptowcm.ear/ilwwcm.war/jsp/html. -
Open the following URL to render
JDRPrint.jsp:http://host:port/wps/wcm/jsp/html/JDRPrint.jsp -
Verify the output entry in
SystemOut.log.