Eclipse cannot find tld inside jar file

3.5k views Asked by At

I have a jar file that contains some tag-files.

My *.tag files are inside /META-INF/tags/ folder (jar)

I also have a mytags.tld inside /META-INF/ folder (jar)

After pack all war project (with mytags.jar inside WEB-INF/lib folder), it works fine in JBoss. But Eclipse still cannot recognize the tag, getting the error Can not find the tag library descriptor for "http://www.mycompany.com"


Is there a way to Eclipse recognize my tags?


follow the sources:

block.tag

<%@tag description="Item do block" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@attribute name="id" required="true" %>
<%@attribute name="label" required="true" %>
<%@attribute name="description" required="false" %>
<%@attribute name="icon" required="false" %>

<div id="${id}" class="block">
    <div class="block-box ${icon}">
        <div class="label">
            <span>${label}</span>
        </div>
        <div class="description">
            ${description}
            <jsp:doBody></jsp:doBody>
        </div>
    </div>
</div>


mytags.tld

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

    <description>My Tags</description>
    <display-name>MyTags</display-name>
    <tlib-version>1.0</tlib-version>
    <short-name>mytags</short-name>
    <uri>http://www.mycompany.com</uri>

    <tag-file>
        <name>block</name>
        <path>/META-INF/tags/block.tag</path>
    </tag-file>
</taglib>


some.jsp

<%@page contentType="text/html; charset=ISO-8859-1" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.mycompany.com" prefix="mytags" %> <-- ECLIPSE MARKS ERROR HERE
<!DOCTYPE html>
<html>

    <head>
        <title>Test</title>
    </head>
    <body>
        <mytags:block id="users" label="Users" icon="user">
            <!-- some content -->
        </mytags:block>
    </body>
</html>

But everything works fine in JBoss. Only eclipse accuses error.

Thanks

1

There are 1 answers

0
eel ghEEz On

An existing bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=330405 suggests correcting the error message to point to the JSP version 1.1 detected from web.xml as a reason for the outdated interpretation of the taglib URI.

This is confirmed by a JSP Tag Libraries document, http://docs.oracle.com/cd/B14099_19/web.1012/b14014/taglibs.htm#i1014427:

As first defined in the JSP 1.1 specification, the taglib directive of a JSP page can fully specify the name and physical location, within a WAR file structure, of the TLD file that defines a particular tag library, as in the following example:

<%@ taglib uri="/WEB-INF/oracustomtags/tlds/mytld.tld" prefix="oracust" %>

[..] Alternatively, as also defined since the JSP 1.1 specification, the taglib directive can specify the name and application-relative physical location of a JAR file instead of a TLD file

Both of the above 2 conventions retired to a fallback mechanism since JSP 1.2 which introduced mapping tag definitions and uses through the arbitrary taglib uri strings, http://docs.oracle.com/cd/B14099_19/web.1012/b14014/taglibs.htm#i1013109.

A recent JSP 2.1 spec documents the URI mapping in section JSP.7.3.2:

The URI describing a tag library is mapped to a TLD resource path though a taglib map, and a fallback interpretation that is to be used if the map does not contain the URI. The taglib map is built from an explicit taglib map in web.xml (described in Section JSP.7.3.3) that is extended with implicit entries deduced from packaged tag libraries in the web application (described in Section JSP.7.3.4), and implicit entries known to the JSP container. The fallback interpretation is targetted to a casual use of the mechanism, as in the development cycle of theWeb Application; in that case the URI is interpreted as a direct path to the TLD (see Section JSP.7.3.6.2).