Eclipse 2021-06
I've ran into a similar issue with Eclipse 2021-06 today:
cvc-id.3: A field of identity constraint 'web-common-filter-name-uniqueness' matched element 'web-app', but this element does not have a simple type.
Wrong answers
Many of the other suggestions in the answers are simply wrong, because what they are doing is changing namespaces to something not mapped to any schema at all anymore and therefore things won't simply be checked anymore. Some comments make that clear already, so java
to Java
or http
to https
or javaee
to j2ee
at some places really only hides the problem.
The point is that if that message comes, there really is a validation problem which needs to be found and fixed. So while suggestions like cleaning the project, the network cache of Eclipse under Windows/Preferences/Network Connections/Cache
etc. are usual Voodoo, they MIGHT(!) work! Though, that wasn't the problem in my case.
Deployment descriptor 3.1
What has worked in my case was changing the deployment descriptor to version 3.1:
<web-app 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-app_3_0.xsd"
id="WebApp_ID" version="3.0">
vs.
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
Afterwards the validation errors were instantly gone. Though, the important part is that in contrast to introduce invalid/unknown/wrong/... namespaces like in many of the other answers, Eclipse DOES validate! This can easily be tested by really adding the same filter-name
twice, which results in the following error:
cvc-identity-constraint.4.1: Duplicate unique value [UrlRewriteFilter]
declared for identity constraint "web-common-filter-name-uniqueness" of
element "web-app".
That DOES NOT happen with invalid/unknown/wrong/... namespaces, Eclipse wouldn't simply validate at all and the error would be left unrecognized until deployment or even later.
Support for version 3.1 in Tomcat+Eclipse
I need to support legacy apps myself, so checked with which version of Tomcat a corresponding web.xml
has been deployed and its 8.0. That should be old enough for a lot of users. Of course Eclipse seems to bundle that version for quite some time as well, otherwise it wouldn't be able to validate right now. Just have a look into the file org.eclipse.jst.standard.schemas_1.2.400.v202101070609.jar
.
Changes of 3.0 to 3.1
I've diffed both versions and it seems people mostly changed only namespaces and migrated some types from the associated web-common_*.xsd
to web-app_*.xsd
itself. Really only minor changes otherwise.
Conclusion
The overall interesting question is why Eclipse stopped working for the former web.xml
even though it seems that it was totally correct. Only the namespaces and version number changed, but that worked for years in the past. What I'm not sure about anymore is if older Eclipse validated using language server, like the currently used version does. I wonder if whatever provides the language server might have changed and version 3.0 of the deployment descriptor might simply not be supported at all anymore.
Or something else changed regarding downloading and including the web-common_*.xsd
and that's why they needed to refactor types into the parent file.
Of course, neither of this was the issue when the question was actually written in 2010. :-) Though, as the deployment descriptor looks still correct to me, only for some older version, there surely was some other root cause as well than wrong namespaces or alike.
JSP-related updates
I've ran into pretty much the problem with JSP as well and this time it was enough to change the location of the XSD only, without any namespace or version changes. The latter were applied for web.xml
, but this time I only did the following:
<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">
vs.
<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://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd
vs.
http://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd
The important thing is that I didn't simply invalidated namespaces, but validation still applies. This can easily be tested by adding invalid elements or e.g. add multiple functions with the same names.
cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://java.sun.com/xml/ns/javaee":foobar}'. One of '{"http://java.sun.com/xml/ns/javaee":description, "http://java.sun.com/xml/ns/javaee":display-name, "http://java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/ns/javaee":tlib-version}' is expected.
WWD in Eclipse contains some catalog file mapping the same actual XSD file under multiple different URI-names. So while in theory the older URI should still be available and used, it doesn't seem to be for some reason. OTOH, the newer URI seems to work for some reason, but in those cases it is necessary to keep the OLD namespaces! Reason simply is that the one and only available file still contains the old namespaces, regardless which URI is used to read it.
<uri name="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" uri="file:///C:/Users/tschoening/AppData/Roaming/Eclipse/Java%20Docsrv/configuration/org.eclipse.osgi/1360/0/.cp/dtdsAndSchemas/web-jsptaglibrary_2_1.xsd"/>
<uri name="http://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" uri="file:///C:/Users/tschoening/AppData/Roaming/Eclipse/Java%20Docsrv/configuration/org.eclipse.osgi/1360/0/.cp/dtdsAndSchemas/web-jsptaglibrary_2_1.xsd"/>
So, it might be that changing the URI only might have worked with web.xml
as well, like it seems to work with my JSP taglibs. Didn't get anything newer to work as well, seems like standards have changed a bit and I would need to adopt more, which I don't want anymore. Legacy-stuff... :-)
servlet-name
. Can we see the whole file, not just that one bit? – Caudill