2

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

ethanxyz_0
  • 713
  • 12
  • 37
  • Which *version* of Eclipse? And if you revalidate the JSP, does the message go away? – nitind Aug 14 '13 at 23:11
  • Eclipse Kepler. No, the message doesn't go away after revalidate the JSP – ethanxyz_0 Aug 15 '13 at 13:44
  • Is the project a Dynamic Web Project with the jar in its WebContent/WEB-INF/lib folder, or otherwise on the Java Build Path? – nitind Aug 15 '13 at 14:11
  • The project is a Dynamic Web Project, but the jars are referenced (in Java Build Path) to the maven repository. But I'm not using m2eclipse. – ethanxyz_0 Aug 15 '13 at 20:48
  • Are the jars physically readable by Eclipse? – nitind Aug 16 '13 at 04:18
  • yes, the jar is in my local maven repository. And I can find it in Package Explorer > Referenced libraries. – ethanxyz_0 Aug 17 '13 at 16:49
  • Sounds like this is worth a bug report then (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=WTP%20Source%20Editing&component=jst.jsp&version=3.5). It certainly sounds like you've got everything set up in ways that should work. – nitind Aug 20 '13 at 15:04

1 Answers1

1

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).

eel ghEEz
  • 1,186
  • 11
  • 24