I am trying to fix a small issue regarding the deployment descriptor of a project I am working on. For some reason, Eclipse doesn't validate the XML file against the DTD but i can't figure why.
Here's the xml file :
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" id="Application_ID" version="1.4">
<display-name>projectName-ear</display-name>
<module id="WebModule_1266621716287">
<web>
<web-uri>projectName-war.war</web-uri>
<context-root>projectName-war</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
And here's the error I have from eclipse validator :
cvc-complex-type.2.4.a: Invalid content was found starting with element 'library-directory'. One of '{"http://java.sun.com/xml/ns/j2ee":module, "http://java.sun.com/xml/ns/j2ee":security-role}' is expected.
The <library-directory>
was introduced in Java EE 5. However, you declared the application.xml
as a J2EE 1.4 application instead of a Java EE 5 application.
<application ... version="1.4">
So it'll run in J2EE 1.4 backwards compatibility modus and not support the <library-directory>
at all.
For a Java EE 5 application (GlassFish 2, JBoss AS 4/5, WebSphere 6, etc), use the below as root declaration:
<application 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/application_5.xsd"
version="5">
Or if you're actually targeting a Java EE 6 container (GlassFish 3, JBoss AS 6/7, WebSphere 7, TomEE 1, etc), then better use the below as root declaration:
<application 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/application_6.xsd"
version="6">
Or if you're actually targeting a Java EE 7 container (GlassFish 4, WildFly 8, WebSphere 8, TomEE 2, etc), then better use the below as root declaration (note the new XML namespace domain):
<application 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/application_7.xsd"
version="7">
Do note that the same applies to other DD XML files such as Servlet's web.xml
, JSF's faces-config.xml
, CDI's beans.xml
, etc. The root XML element declaration and its version
is very significant!