My web-app declaration in my web.xml is:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
And eclipse complains about all 4 attributes, here is one Eclipse complaint:
Attribute "version" must be declared for element type "web-app"
Why is Eclipse complaining about these attributes? Am I doing something wrong here?
Didn't you forget this row in your xml file?:
Your file should start like this:
If it doesn't work clean and refresh your project.
Just remove the DOCTYPE. And its works fine.
I had the same problem. I tried a different schema location and it worked for me. Instead of
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
try using this
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
Also, set the version as
"3.0"
.Remove the DOCTYPE line, that is what the xsd is meant to replace. I had the same issue and only this had worked.
Refer to this oracle.com link to know what all were announced with Java EE 7 (assuming that is what we're working with). The link states
The namespace
java.sun
has not becomejava.oracle
, instead it has been retained by The Java Community Process (JCP). Hence all namespaces should point to xmlns.jcp.org, as is also pointed out by Java EE 7 docs.Now, when we are deploying a web application (and hence the need to define a web.xml), first we have to know what we intend to do.
Say, we are working with Apache Tomcat V8. If we read the docs here, we get to know that it comes with Servlet 3.1 bundled. So, I would prefer an implementation of Servlet 3.1, just to stay up to date if not anything else.
Now all that being said, this is the declaration I would have
Hope this answers the question.
I changed the declaration from
http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
to the following and it worked like charm. Now no errors shown in web.xml
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">