1

Can anyone help me? I'm creating a new Dynamic Web Project on Eclipse 2021-06 with Apache Tomacat 10. I'm always receving errors in web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app    id="WebApp_ID" version="2.5" 
            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">
    <display-name>01Test</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Have marks on:

  • version="2.5

I receive the following errors enter image description here

How can i solve??? I tried downloading Tomcat form website and through Eclipse... With Web module 4 and 5... but still have this problem...

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • 1
    Please open a bug report for this error in the generated deployment descriptor file. – nitind Aug 19 '21 at 14:22
  • Where did you get the `id` element in the `web-app` element? I can't find a reference to that anywhere and I don't believe it's valid. – stdunbar Aug 19 '21 at 17:33

1 Answers1

2

Eclipse validates the web.xml file against the provided schema:

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd

that schema requires the version attribute to be 2.4. If you set it to the correct value 2.4 the error will disappear. Also Servlet 2.4 didn't have a <display-name> tag, hence the second "error".

Since Tomcat 5.5 (which supported Servlet 2.4) is long gone, you should change the schema of your web.xml to either:

  • Servlet 3.1, corresponding to the oldest version of Tomcat that didn't reach end-of-life (Tomcat 8.5):

    <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"
        version="3.1">
    
  • Servlet 4.0, corresponding to the last version ever under the Java EE name:

    <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_4_0.xsd"
        version="4.0">
    
  • Servlet 5.0, corresponding to Tomcat 10:

    <web-app
        xmlns="https://jakarta.ee/xml/ns/jakartaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
        version="5.0">
    

and set the version of the "Dynamic Web Module" facet accordingly. This way Eclipse will provide you with completion suggestions for the elements that were introduced in those specifications.

Remark: Maybe it has been corrected since, but Eclipse 2021-03 had still some quirks in the support of Tomcat 10 and Jakarta EE 9. E.g. it didn't allow to deploy a Servlet 5.0 project on Tomcat 10, it worked only with Servlet 4.0 projects and older.

You need also to be aware, that due to the migration from the javax.* to the jakarta.* namespace, your project will not work on older versions of Tomcat.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • 1
    If you are seeing quirks 2021-06, please open bug reports for them. – nitind Aug 19 '21 at 14:27
  • @nitind: sorry, that would of course be the correct thing to do. But the temptation to just walk around those bugs instead of helping fixing them is great. :-) – Piotr P. Karwasz Aug 19 '21 at 21:54