Java EE 7 Deployment Descriptors

As you might know by now, Java EE 7 will be released in a few days. There are many new features and I will not cover these novelties now. I just want to mention that most of the XML deployment descriptor namespaces have been updated. Nothing that will change your life as a developer, but as I mentioned on the Aquarium blogIt’s a symbol. For many years we were wondering what would happen to java.sun.com namespaces. Most of us thought it would be renamed to java.oracle.com. But no, it went back to where it originally belonged, to the JCP. Lately the JCP has moved towards greater transparency (i.e. JCP.next) and having the JCP namespaces strenghens this move“.

Basically, instead of having http://java.sun.com/xml/ns/javaee use http://xmlns.jcp.org/xml/ns/javaee. And of course, most of the XSD version numbers have been updated. So here are some of the new Java EE 7 namespaces.

CDI 1.1

The CDI deployment descriptor (beans.xml) is mandatory, even if it stays totally empty. Note that in CDI 1.1 (JSR 346) there is a new bean-discovery-mode element that informs CDI to discover all beans, none, or only annotated ones.

[sourcecode language=”xml” title=”beans.xml”]
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd&quot;
version="1.1" bean-discovery-mode="all">
</beans>
[/sourcecode]

Bean Validation 1.1

Bean Validation 1.1 (JSR 349) is the only specification that hasn’t updated the namespace and still uses http://jboss.org/xml/ns. Note that Bean Validation and CDI specifications are both lead by RedHat

[sourcecode language=”xml” title=”validation.xml”]
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd"
version="1.1">
</validation-config>
[/sourcecode]

 

[sourcecode language=”xml” title=”constraints.xml”]
<constraint-mappings
xmlns="http://jboss.org/xml/ns/javax/validation/mapping&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd"
version="1.1">
</constraint-mappings>
[/sourcecode]

JPA 2.1

Only mandatory deployment descriptor in Java EE 7, the JPA 2.1 (JSR 338persistence.xml files introduces new standard properties for schema generation (more on that in a coming post).

[sourcecode language=”xml” title=”persistence.xml”]
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd&quot;
version="2.1">
</persistence>
[/sourcecode]

 

[sourcecode language=”xml” title=”mapping.xml”]
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd&quot;
version="2.1">
</entity-mappings>
[/sourcecode]

EJB 3.2

Not many changes in EJB 3.2 (JSR 342) compared to 3.1. So the ejb-jar.xml gently follows these minor updates.

[sourcecode language=”xml” title=”ejb-jar.xml”]
<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd&quot;
version="3.2">
</ejb-jar>
[/sourcecode]

Servlet 3.1

Like the previous release, the web.xml in Servlet 3.1 (JSR 340) is optional as well as the web-fragment.xml.

[sourcecode language=”xml” title=”web.xml”]
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot;
version="3.1">
</web-app>
[/sourcecode]

JSF 2.2

In JSF 2.2 (JSR 344) the faces-config.xml is still optional. Note that the namespaces of the component libraries have also been updated

[sourcecode language=”xml” title=”faces-config.xml”]
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd&quot;
version="2.2">
</faces-config>
[/sourcecode]

 

[sourcecode language=”xml” title=”aJSFPage.xhtml”]
<html xmlns="http://www.w3.org/1999/xhtml&quot;
xmlns:h="http://xmlns.jcp.org/jsf/html&quot;
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&gt;
</html>
[/sourcecode]

JAX-WS 2.2

The WS-* landscape is defined in several specifications (JAX-WS 2.2a with JSR 224, Web Services 1.4 with JSR 109 and Web Services Metadata 2.1 with JSR 181). The webservices.xml deployment descriptor has been updated with the new namespace.

[sourcecode language=”xml” title=”webservices.xml”]
<webservices xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/javaee_web_services_1_4.xsd&quot;
version="1.4">
</webservices>
[/sourcecode]

Conclusion

When you develop a Java EE 7 application make sure to use the new namespaces. I’ve just listed here the most common deployment descriptors but Java EE 7 has several extra ones (javaee_7.xsd, application_7.xsd, application-client_7.xsd, batchXML_1_0.xsd, jobXML_1_0.xsd…)).

8 thoughts on “Java EE 7 Deployment Descriptors

      1. In JPA 2.1 specification (§12.3) it states “The file may be named “META-INF/orm.xml” in the persistence archive or it may be named some other name which would be used to locate the file as resource on the classpath.”

  1. One thing to note on the aJSFPage.xhtml for Eclipse IDE to not render any warnings you need to specify a JSF implementation in your classpath. However, I have yet to see one that actually uses the new xmlns.jcp.org version, alI saw were still the java.sun.com versions in their TLD files.

Leave a Reply