Java Eclipse“无法找到自定义标签的标签库描述符”(不是 JSTL!)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1265309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 07:36:17  来源:igfitidea点击:

Eclipse "cannot find the tag library descriptor" for custom tags (not JSTL!)

javaeclipsejsptaglibcustom-tags

提问by ryandenki

I have a Java EE project which build fine with Ant, deploys perfectly to JBoss, and runs without any trouble. This project includes a few customtag libraries (which is not JSTL!), which are also working without any difficulties.

我有一个 Java EE 项目,它用 Ant 构建得很好,完美地部署到 JBoss,并且运行没有任何问题。该项目包括一些自定义标记库(不是JSTL!),它们也可以毫无困难地工作。

The problem is with the Eclipse IDE (Ganymede): in every single JSP file which uses our custom tags, the JSP parser flags the taglib include line with with this error:

问题出在 Eclipse IDE (Ganymede) 上:在每个使用我们自定义标签的 JSP 文件中,JSP 解析器都会标记带有以下错误的 taglib include 行:

Cannot find the tag library descriptor for (example).tld

Cannot find the tag library descriptor for (example).tld

This also causes every use of the tab library to be flagged as an error, and since the IDE doesn't have their definition, it can't check tag parameters, etc.

这也会导致标签库的每次使用都被标记为错误,并且由于 IDE 没有它们的定义,它无法检查标签参数等。

Our perfectly-working JSP files are a sea of red errors, and my eyes are beginning to burn.

我们完美运行的 JSP 文件是一片红色错误的海洋,我的眼睛开始燃烧。

How can I simply tell Eclipse, "The tag library descriptor you are looking for is "src/web/WEB-INF/(example)-taglib/(example).tld"?

我怎么能简单地告诉 Eclipse,“您要查找的标签库描述符是“src/web/WEB-INF/(example)-taglib/(example).tld”?

I've already asked this question on the Eclipse support forums, with no helpful results.

我已经在 Eclipse 支持论坛上问过这个问题,但没有任何有用的结果。

采纳答案by ryandenki

It turns out that the cause was that this project wasn't being considered by Eclipse to actually be a Java EE project at all; it was an old project from 3.1, and the Eclipse 3.5 we are using now requires several "natures" to be set in the project configuration file.

事实证明,原因是 Eclipse 根本不认为该项目实际上是一个 Java EE 项目;这是一个来自 3.1 的旧项目,我们现在使用的 Eclipse 3.5 需要在项目配置文件中设置几个“性质”。

<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>InCode.inCodeNature</nature>
    <nature>org.eclipse.dltk.javascript.core.nature</nature>
    <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
    <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
</natures>

I was able to find the cause by creating a new "Dynamic Web Project" which properly read its JSP files, and diffing against the config of the older project.

我能够通过创建一个正确读取其 JSP 文件的新“动态 Web 项目”并与旧项目的配置进行比较来找到原因。

The only way I could find to add these was by editing the .project file, but after re-opening the project, everything magically worked. The settings referenced by pribeiro, above, weren't necessary since the project already conformed to the default settings.

我能找到添加这些的唯一方法是编辑 .project 文件,但在重新打开项目后,一切都神奇地工作了。上面 pribeiro 引用的设置不是必需的,因为项目已经符合默认设置。

Both pribeiro and nitind's answers gave me ideas to jumpstart my search, thanks.

pribeiro 和 nitind 的回答都给了我开始搜索的想法,谢谢。

Is there a way of editing these "natures" from within the UI?

有没有办法从用户界面中编辑这些“性质”?

回答by nitind

A lot depends on what kind of project it is. WTP's JSP support either expects the JSP files to be under the same folder that's the parent of the WEB-INF folder (src/web, which it will then treat as "/" to find TLDs), or to have project metadata set up to help it know where that root is (done for you in a Dynamic Web Project through Deployment Assembly). How are you referring to the TLD file, and where is the JSP file located?

很大程度上取决于它是什么类型的项目。WTP 的 JSP 支持要么期望 JSP 文件位于 WEB-INF 文件夹(src/web,然后将其视为“/”以查找 TLD)的父文件夹下,要么将项目元数据设置为帮助它知道根在哪里(通过部署程序集在动态 Web 项目中为您完成)。您如何引用 TLD 文件,JSP 文件位于何处?

And maybe I missed the original post to the Eclipse forums; the one I saw was posted a full day after this one.

也许我错过了 Eclipse 论坛的原始帖子;我看到的那个是在这个之后一整天发布的。

回答by pribeiro

I fixed this problem today.

我今天解决了这个问题。

  • Change your output directory to your WEB-INF/classes folder. (Project/Properties/Java Build Path, Default output folder)
  • Assigne the module dependencies. (Project/Properties/Java EE Module Dependencies) they will be copied to the WEB-INF/lib folder where Eclipse looks for the tag lib definitions too.
  • 将输出目录更改为 WEB-INF/classes 文件夹。(项目/属性/Java 构建路径,默认输出文件夹)
  • 分配模块依赖项。(项目/属性/Java EE 模块依赖项)它们将被复制到 WEB-INF/lib 文件夹中,Eclipse 也会在其中查找标签库定义。

I hope it helps.

我希望它有帮助。

回答by user335669

I had the same problem with MyEclipse and Eclipse 6.6.0. It red lined the uri value in every

我在 MyEclipse 和 Eclipse 6.6.0 上遇到了同样的问题。它在每个 uri 值上标红线

<%@ taglib prefix="s" uri="/struts-tags"%>. I fixed it by going to 'Project/MyEclipse/Web/Tag Libraries' and setting the Default TLD Prefix for Struts 1.2 Tiles Tags to 's'. I also had to do the same under 'Project/MyEclipse/Web/Configure workspace settings.../Tag Libraries'.

<%@ taglib prefix="s" uri="/struts-tags"%>. 我通过转到“Project/MyEclipse/Web/Tag Libraries”并将Struts 1.2 Tiles 标签的默认TLD 前缀设置为“s”来修复它。我还必须在“项目/MyEclipse/Web/配置工作区设置.../标签库”下做同样的事情。

回答by Polaris878

This was my problem and how I fixed it...

这是我的问题以及我如何解决它...

I had done everything everyone had mentioned above etc. but was still getting this error. Turns out I was using the uri's of http://java.sun.com/jsp/jstl/fmtand http://java.sun.com/jsp/jstl/corewhich were incorrect.

我已经完成了上面每个人提到的一切,但仍然出现此错误。原来我用的URI的http://java.sun.com/jsp/jstl/fmthttp://java.sun.com/jsp/jstl/core哪些是不正确的。

Try switching the uris from above to:

尝试将 uris 从上面切换到:

http://java.sun.com/jstl/fmt
http://java.sun.com/jstl/core

Also, make sure you have the correct jars referenced in your class path.

另外,请确保您在类路径中引用了正确的 jar。

回答by stivlo

In Eclipse Helios "Java EE Module Dependencies" in the project properties has been replaced with "Deployment Assembly".

在 Eclipse Helios 中,项目属性中的“Java EE 模块依赖项”已替换为“部署程序集”。

So for solving this problem with Eclipse Helios, the way I did it is the following:

所以为了用 Eclipse Helios 解决这个问题,我的方法如下:

  • Right click on the project in package explorer and choose "Import..."
  • Accept the default selection "File System" and press "Next"
  • Press "Browse" in the From directory line, go to your tomcat installation and locate the file webapps/examples/WEB-INF/lib (I have tomcat 6, other versions of Tomcat may have the path webapps/jsp-examples/WEB-INF/lib). Once in the path press OK.
  • Click besides jstl.jar and standard.jar to activate the check boxes
  • On the line Into folder click on Browse and choose the library folder. I use /lib inside the project.
  • Click "Finish"
  • Right click on the project in Package Explorer view and choose properties (or press Alt + Enter)
  • Click on "Java Build Path"
  • Click "Add Jar", click on your project, folder lib, select jstl.jar, press OK
  • Click "Add Jar", click on your project, folder lib, select standard.jar, press OK
  • Press OK to dismiss the properties dialog
  • Click on the Problems view and select the message "Classpath entry .../jstl.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.".
  • Right click on it and select "Quick Fix".
  • Accept the default "Mark the associated raw classpath entry as a publish/export dependency" and press Finish.
  • Do the same for standard.jar
  • 右键单击包资源管理器中的项目并选择“导入...”
  • 接受默认选择“文件系统”,然后按“下一步”
  • 在 From 目录行中按“Browse”,转到您的 tomcat 安装并找到文件 webapps/examples/WEB-INF/lib(我有 tomcat 6,其他版本的 Tomcat 可能有路径 webapps/jsp-examples/WEB- INF/lib)。进入路径后,按 OK。
  • 单击 jstl.jar 和 standard.jar 旁边的复选框以激活复选框
  • 在进入文件夹行上,单击浏览并选择库文件夹。我在项目中使用 /lib 。
  • 点击“完成”
  • 在 Package Explorer 视图中右键单击项目并选择属性(或按 Alt + Enter)
  • 单击“Java 构建路径”
  • 点击“Add Jar”,点击你的项目,文件夹lib,选择jstl.jar,点击OK
  • 点击“Add Jar”,点击你的项目,文件夹lib,选择standard.jar,点击OK
  • 按 OK 关闭属性对话框
  • 单击问题视图并选择消息“类路径条目 .../jstl.jar 将不会被导出或发布。可能会导致运行时 ClassNotFoundExceptions。”。
  • 右键单击它并选择“快速修复”。
  • 接受默认的“将关联的原始类路径条目标记为发布/导出依赖项”并按完成。
  • 对standard.jar 做同样的事情

This solves the problem, but if you want to check what has happened in "Deployment Assembly", open the project properties again, select "Deployment Assembly" and you'll see that standard.jar and jstl.jar have been added to WEB-INF/lib folder.

这样就解决了问题,但是如果你想查看“Deployment Assembly”中发生了什么,再次打开项目属性,选择“Deployment Assembly”,你会看到已经在WEB中添加了standard.jar和jstl.jar—— INF/lib 文件夹。

回答by Buminda

Check the two libraries in F:\apache-tomcat-7.0.21\webapps\examples\WEB-INF\lib:

检查两个库F:\apache-tomcat-7.0.21\webapps\examples\WEB-INF\lib

  1. jstl.jar
  2. standard.jar
  1. 文件
  2. 标准文件

回答by Patrick Garner

You can simply go to Build Path -> Add Libraries and for the library type to add select "Server Runtime." Click Next and select a server runtime to add to the classpath and the problem goes away if jstl.jar and standard.jar are in your server's classpath.

您只需转到 Build Path -> Add Libraries 并为要添加的库类型选择“Server Runtime”。单击下一步并选择要添加到类路径的服务器运行时,如果 jstl.jar 和 standard.jar 位于服务器的类路径中,问题就会消失。

回答by Mark J Miller

Ran into the same problem, I'm using maven so I added this to the pom in my web project:

遇到了同样的问题,我使用的是 maven,所以我将它添加到我的 web 项目的 pom 中:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version> <!-- just used the latest version, make sure you use the one you need -->
    <scope>provided</scope>
</dependency>

This fixed the problem and I used "provided" scope because like the OP, everything was already working in JBoss.

这解决了这个问题,我使用了“提供的”范围,因为像 OP 一样,一切都已经在 J​​Boss 中工作了。

Here's where I found the solution: http://alfredjava.wordpress.com/2008/12/22/jstl-connot-resolved/

这是我找到解决方案的地方:http: //alfredjava.wordpress.com/2008/12/22/jstl-connot-resolved/

回答by Philip Murphy

I had the same problem with a stripes taglib uri showing as not found. I was using Indigo and Maven and when I checked Properties->Java Build Path->Order & Export Tab I found (on a fresh project checkout) that the "Maven Dependencies" checkbox was unchecked for some reason. Simply checking that box and doing a Maven clean install cleared all the errors.

我对显示未找到的条纹 taglib uri 有同样的问题。我正在使用 Indigo 和 Maven,当我检查 Properties->Java Build Path->Order & Export Tab 时,我发现(在新的项目结帐中)由于某种原因未选中“Maven Dependencies”复选框。只需选中该框并执行 Maven 全新安装即可清除所有错误。

I wonder why Eclipse doesn't assume I want my Maven dependencies in the build path...

我想知道为什么 Eclipse 不假设我想要我的 Maven 依赖项在构建路径中......