6

I am building a web application in Eclipse and get a version issue in web.xml:

<web-app version="2.4" xmlns="java.sun.com/xml/ns/javaee"
   xmlns:xsi="w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="java.sun.com/xml/ns/javaee java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

The error is:

cvc-enumeration-valid: Value '2.4' is not facet-valid with respect to enumeration '[2.5]'.
It must be a value from the enumeration.

The project facet shows version 2.4 for both the Dynamic Web Module and the Servlet API.

zb226
  • 9,586
  • 6
  • 49
  • 79
lowLatency
  • 5,534
  • 12
  • 44
  • 70

1 Answers1

9

If you declare your app in Eclipse to be a 2.5 app, and say that your web-app version is 2.4, but link to the schema of the 2.5 version (web-app_2_5.xsd), it will obviously not work

<web-app version="2.4" 
         xmlns="java.sun.com/xml/ns/javaee"
         xmlns:xsi="w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="java.sun.com/xml/ns/javaee 
                             java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                                                                 ^-- HERE!

Use the 2.4 version:

<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">
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks JB for solving the problem – lowLatency Jan 19 '12 at 09:26
  • Why will it not obviously work? What does the schemaLocation change? – Koray Tugay Sep 27 '14 at 10:26
  • @KorayTugay If you compare the [2.4 XSD](http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd) with the [2.5 XSD](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd), you will find the type definition for `web-app-versionType`, which restricts its value to the respective version number. This is what Eclipse validates against, and thus, in the given case, fails. – zb226 Sep 27 '18 at 22:45