Search code examples
javaspring-bootweb.xmltaglibtld

Tomcat 8 cannot find custom tlds


I had made a web site with spring boot. Now, I want to convert this to could be deployed in Tomcat 8. After converting it, Tomcat 8 is unable to find my custom TLD file, even when I set 'taglib-location' at the web.xml.

Here is my project source

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0">

    <!-- tld -->
    <jsp-config>
        <taglib>
            <taglib-uri>/tld/code-generator.tld</taglib-uri>
            <taglib-location>/WEB-INF/tld/code-generator.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>

code-generator.tld

<?xml version="1.0" encoding="UTF-8" ?>

<taglib version="2.1"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" >

    <tlib-version>1.0</tlib-version>
    <short-name>cdg</short-name>
    <uri>/WEB-INF/tld/code-generator.tld</uri>

    <function>
        <name>toCodeString</name>
        <function-class>com.msh.nia.util.CodeGenerator</function-class>
        <function-signature>java.lang.String toCodeString(java.lang.String)</function-signature>
    </function>

  ... etc

index.jsp

<%@ taglib prefix="cdg" uri="/tld/code-generator.tld" %>

directory structure : structure image


Errors and warning

정보: Starting Servlet Engine: Apache Tomcat/8.5.34
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJspConfig
경고: Failed to process TLD with path [/WEB-INF/tld/code-generator.tld] and URI [/tld/code-generator.tld]. The specified path does not exist.
10월 17, 2018 11:48:05 오후 org.apache.jasper.servlet.TldScanner scanJars
정보: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
10월 17, 2018 11:48:05 오후 org.apache.catalina.core.ApplicationContext log
정보: 2 Spring WebApplicationInitializers detected on classpath

...

2018-10-17 23:48:16.026  INFO 73568 --- [           main] o.a.c.s.Catalina                         : Server startup in 14987 ms
2018-10-17 23:48:16.314 ERROR 73568 --- [nio-8080-exec-9] o.s.b.w.s.s.ErrorPageFilter              : Forwarding to error page from request [/index.jsp] due to exception [Unable to find taglib [cdg] for URI: [tld/code-generator.tld]]

org.apache.jasper.JasperException: Unable to find taglib [cdg] for URI: [tld/code-generator.tld]
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55) ~[jasper.jar:8.5.34]
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:293) ~[jasper.jar:8.5.34]
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:80) ~[jasper.jar:8.5.34]
    at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181) ~[jasper.jar:8.5.34]
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431) ~[jasper.jar:8.5.34]
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489) ~[jasper.jar:8.5.34]

Solution

  • It appears that you are giving an absolute path in the taglib-location element of your web.xml file.

    Try this:

    <taglib-location>WEB-INF/tld/code-generator.tld</taglib-location>
    

    Notice that there is no "/" before the "WEB-INF" in the element value.