ChatGPT解决这个技术问题 Extra ChatGPT

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

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 custom tag libraries (which is not JSTL!), which are also working without any difficulties.

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:

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.

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

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

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

This question is full of nonsense answers. The question is NOT about JSTL, but about real homegrown custom JSP tags in an user-defined foo.tld file. The real question and answer about how to install JSTL can be found here: Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

s
stivlo

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

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

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

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.


also Works with Eclipse 4.4.0 (Luna)
Works great with Mars too
This answer only describes how to install JSTL (in a devious way) and does therefore not answer OP's concrete problem with custom taglibs. The real answer to OP's problem is below. How to actually install JSTL the right way is answered here: Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”.
P
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/fmt and http://java.sun.com/jsp/jstl/core which were incorrect.

Try switching the uris from above to:

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.


If you want JSTL 1.2 then use http://java.sun.com/jsp/jstl/* for JSTL 1.0 use http://java.sun.com/jstl/*.
Thanks, that worked. At the same time I could run project without errors in NetBeans with the http://java.sun.com/jsp/jstl/core which confuses me a little.
P
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.

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


What do you mean my Maven Clean install? I mean, I don't see anything looking like that in options provided by "Right Click on project" >> Maven. Doing a mvn clean install at the command line seems completely unrelated. FYI: my project runs fine if I deploy it on Tomcat "alone" but when running in Eclipse it throws "The absolute uri: java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application". Maybe I should simply use Eclipse as a fancy editor & stop expecting much more from it.
When I changed the Nexus repository I was pointing to in my organisation, the result was the OP's original error. I found then found that the Maven dependencies checkbox was unchecked (after reading your answer). So I checked it and it rebuilt the project but the error was still there. I then ran right-click->Maven->Update Maven project with the "force update of snapshots/releases" checked and the error disappeared. However when I looked in the Order & Export tab again, the "Maven Dependencies" was unchecked! This is repeatable. However at least the error is gone.
A
Arjan Tijms

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.

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

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.

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

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


The 'Project Facets' in the project properties may be the way. I faced a similar "cannot find tag library descriptor" problem which got fixed when I checked the correct project type under Project Facets.
M
Mark J Miller

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

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

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


T
Tanvir

When I tried to include the JSTL Core Library in my JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

I got the following error in Eclipse (Indigo):

Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"

I went to the Project Properties -> Targeted Runtimes, and then checked the Server I was using (Geronimo 3.0). Most people would be using Tomcat. This solved my problem. Hope it helps!


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

I hope it helps.


Thanks, I didn't know about the module dependencies settings.
My project doesn't have a "Java EE Module Dependencies" in its properties list. Java-related properties are only: BeanInfo Path Java Build Path Java Code Style Java Compiler Java Editor Javadoc Location Is there some other option which must be enabled?
n
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?

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


B
Buminda

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

jstl.jar standard.jar


this would be a better answer with a more general path and with explaining what those libs are and where they can be found for other projects....
R
ROMANIA_engineer

I faced same problem. This is what I did to resolve the issue.

Select Project and right click. Click on properties. Click on libraries tab. Click on 'Add Jars'. Add relevant jar for your error.


The same for me, I don't know why maven didn't put it in the referenced libraries
P
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.


This question was asked and answered in 2009, answering now is less relevant.
T
TalkLittle

I'm using Spring STS plugin and a Spring webmvc template project. I had to install the Maven m2e plugin first: http://www.eclipse.org/m2e/

And then clean the project. Under Project -> Clean...


r
rabiya khan

If your tld's are on the classpath, typically under the WEB-INF directory, the following two tips should resolve the issue (irrespective of your environment setup):

Ensure that the in the TLD and the uri in the taglib directive of your jsp pages match. The element of the tld is a unique name for the tag library. If the tld does not have a element, the Container will attempt to use the uri attribute in the taglib directive as a path to the actual TLD. for e.g. I could have a custom tld file in my WEB-INF folder and use the path to the this tld as the uri value in my JSP. However, this is a bad practice and should be avoided since the paths would then be hardcoded.


That's what fixed my JSP taglib resolution. Thanks.
u
user335669

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

<%@ 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'.


M
Matt Fenwick

I had the same problem with STS (springtool source suite).

Under STS, right click on the project, than "Properties", "Project Facets", than on the right of the window click on the "runtime" tab, and check "VMware vFabric tc Server (...)", and click "Apply" and it should be OK after the workspace refresh.


I
Ismail Marmoush

well you need to understand there are always two things the API and the implementation (mind the gradle format of the following code)

compile group:'javax.servlet.jsp.jstl', name:'javax.servlet.jsp.jstl-api', version:'1.2.1'

compile group:'org.glassfish.web', name:'javax.servlet.jsp.jstl',version:'1.2.1'

so If you're using a servlet container with no jstl support then of course it will not provide both of them, a mistake which I made is that I only put the first one, but if you're using full stack application server i.e glassfish then glassfish will have both of them already inside.


I would appreciate if the downvoter would be a gentleman and say why he is down voting the answer.
B
Barun

For me, this error occurs whenever I try to use a new version of eclipse. Apparently, the new eclipse resets the M2_REPO variable and I get all the tag library error in the Marker view (sometimes with ejb validation errors).

After updating M2_REPO variable to point to actual maven repository location, it takes 2-3 Project -> Clean iterations to get everything working.

And sometimes, there are some xml validation errors(ejb) along with this tag library errors. Manually updating the corresponding XML file, initiates a *.xsd file lookup and the xml validations errors are resolved. Post this, the tag library errors also vanish.


u
user3923794

On the other hand, if you are only working on java source and are getting these errors from stuff you don't touch in a large project that is working, you can just turn off the validations in Eclipse. The settings are under Preferences->Web->JSP Files->Validation


C
Community

I was having the same problem using Tomcat 6.0 and Eclipse and I tried out something which my friend suggested and it worked for me. The link for the question I asked and my reply commented can be found here:

JSTL Tomcat 6.0 Cannot find the taglib descriptor Error

Let me know if this solves your "Cannot find the taglibrary descriptor" problem.


P
Parker

This error can arise from several different sources. One case (not mentioned in other answers to this question) occurs when Eclipse does not implement the version of the JSP specification set in the TLD document. Eclipse releases typically lag behind up to a year in implementing newer servlet and JSP specifications. See this Eclipse bug for example.

In this case, your web application may run fine in the latest version of Tomcat, but Eclipse may still complain about a missing TLD. The short term solution (short of ignoring the error in Eclipse) is to bump down the JSP version to the one that your version of Eclipse supports.

Also, keep in mind the TLD version you are implementing. The tag names have changed slightly from v1.1 to v2.0 (i.e., info is now description on taglib and is not a valid element under tag, many of the element names now contain a hyphen). Eclipse has no tolerance for misspelled TLD tag names.

TLD 2.0 (jsp-version 2.0) Reference

TLD 2.1 (jsp-version 2.3) Reference


s
sathia

replace jstl.jar to jstl1.2.jar resolved the issue for tomcat 7.0


l
likeitlikeit

I also faced the same problem. Make sure you have same versions of JSTL in Eclipse and in the Tomcat work directory, i.e in \webapps\examples\WEB-INF\lib and in lib folder.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now