Issue with creating Custom Tag Libraries in CQ5.5

By : ezhil

I am creating a custom tag library and want to use it in one of my components. I have created a bundle which includes tag hello class which is extending TagSupport class and i created tags.tld file under my resource folder

In my pom.xml, I have used resource tag to include my .tld file in the generated jar file.

Here is my java class and tld file


package com.cb;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* Simple tag example to show how content is added to the
* output stream when a tag is encountered in a JSP page.
public class Hello extends TagSupport {
private String name=null;
   * Getter/Setter for the attribute name
     as defined in the tld file
   * for this tag*/
public void setName(String value){
    name = value;
public String getName(){
* doStartTag is called by the JSP container
  when the tag is encountered */
public int doStartTag() {
  try {
    JspWriter out = pageContext.getOut();
    out.println("<table border=\"1\">");
     if (name != null)
      out.println("<tr><td> Welcome <b>" + name +
        "</b> </td></tr>");
      out.println("<tr><td> Hello World </td></tr></table>");
  } catch (Exception ex) {
    throw new Error("All is not well in the world.");
  // Must return SKIP_BODY because we are not
       //supporting a body for this
  // tag.
  return SKIP_BODY;
* doEndTag is called by the
  JSP container when the tag is closed */
public int doEndTag(){
   return EVAL_PAGE;

I also successfully installed the bundle in my felix console without having any error. Then i written custom tag in my jsp as below


<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="com.testcb.TestCustomTag"%>
<%@ taglib prefix="mytest" uri=""%>
<mytest:hello name="sachin"></mytest:hello>

I am getting the like " /apps/test/components/content/test/test.jsp(4,0) Unable to load tag handler class "com.cb.Hello" for tag "mytest:hello".

The same code is working fine in my apache tomcat server without having any issue. I am getting the error when i incorporate it in CQ.

What am i doing here? Is there any config i need to do in OSGI console to make it available?


There was some problem with package name. Now Sling can read my tag handler class after i renamed the package name.

The error "Unable to load tag handler class" also has gone.

Now i am getting error as " javax.servlet.ServletException: javax.servlet.jsp.JspException: com.testcb.TestCustomTag cannot be cast to javax.servlet.jsp.tagext.Tag"

I have the following dependency in pom.xml


And Here is my tld

<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="" xmlns:xsi="" xsi:schemaLocation="" version="2.0"> 
    <description>My tag library123</description>
      <info>This is a simple hello tag</info>

Is there any problem with jsp version?

Please guide me to resolve.


By : ezhil


Yes, It is working as expected after i removed tag in pom.xml. This was the cause issues. :)

Thanks !

By : ezhil

This video can help you solving your question :)
By: admin