简体   繁体   English

Eclipse在jar文件中找不到TLD

[英]Eclipse cannot find tld inside jar file

I have a jar file that contains some tag-files. 我有一个包含一些标记文件的jar文件。

My *.tag files are inside /META-INF/tags/ folder (jar) 我的*.tag文件位于/META-INF/tags/文件夹(jar)中

I also have a mytags.tld inside /META-INF/ folder (jar) 我在/META-INF/文件夹(jar)中也有一个mytags.tld

After pack all war project (with mytags.jar inside WEB-INF/lib folder), it works fine in JBoss. 打包所有war项目(在WEB-INF/lib文件夹中带有mytags.jar )之后,它在JBoss中可以正常工作。 But Eclipse still cannot recognize the tag, getting the error Can not find the tag library descriptor for "http://www.mycompany.com" 但是Eclipse仍然无法识别标签,并得到错误消息: Can not find the tag library descriptor for "http://www.mycompany.com"


Is there a way to Eclipse recognize my tags? 有没有办法让Eclipse识别我的标签?


follow the sources: 遵循来源:

block.tag 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 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 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. 但是在JBoss中一切正常。 Only eclipse accuses error. 只有日食指责错误。

Thanks 谢谢

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. 现有的错误报告https://bugs.eclipse.org/bugs/show_bug.cgi?id=330405建议更正错误消息,使其指向从web.xml检测到的JSP 1.1版,这是对taglib进行过时解释的原因URI。

This is confirmed by a JSP Tag Libraries document, http://docs.oracle.com/cd/B14099_19/web.1012/b14014/taglibs.htm#i1014427 : 这由JSP标记库文档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: 正如在JSP 1.1规范中首次定义的那样,JSP页面的taglib指令可以在WAR文件结构中完全指定定义特定标记库的TLD文件的名称和物理位置,如以下示例所示:

<%@ 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 [..]另外,正如自JSP 1.1规范以来所定义的那样,taglib指令可以指定JAR文件而不是TLD文件的名称和相对于应用程序的物理位置。

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 . 自从JSP 1.2引入了映射标记定义并通过任意taglib uri字符串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: 最新的JSP 2.1规范在JSP.7.3.2部分记录了URI映射:

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. 描述标签库的URI通过taglib映射映射到TLD资源路径,如果映射不包含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. taglib映射是从web.xml(在JSP.7.3.3中描述)中的显式taglib映射构建的,该映射由从Web应用程序中打包的标签库推断出的隐式条目扩展(在JSP.7.3.4中描述),和JSP容器已知的隐式条目。 The fallback interpretation is targetted to a casual use of the mechanism, as in the development cycle of theWeb Application; 后备解释的目标是随意使用该机制,例如Web应用程序的开发周期。 in that case the URI is interpreted as a direct path to the TLD (see Section JSP.7.3.6.2). 在这种情况下,URI被解释为通往TLD的直接路径(请参见JSP.7.3.6.2节)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM