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.

<beans 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/beans_1_1.xsd"
       version="1.1" bean-discovery-mode="all">
</beans>

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

<validation-config
        xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd"
        version="1.1">
</validation-config>
<constraint-mappings
        xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd"
        version="1.1">
</constraint-mappings>

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).

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
</persistence>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"
                 version="2.1">
</entity-mappings>

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.

<ejb-jar 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/ejb-jar_3_2.xsd"
         version="3.2">
</ejb-jar>

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.

<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">
</web-app>

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

<faces-config 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-facesconfig_2_2.xsd"
              version="2.2">
</faces-config>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
</html>

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.

<webservices 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/javaee_web_services_1_4.xsd"
             version="1.4">
</webservices>

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…)).

About these ads
Comments
5 Responses to “Java EE 7 Deployment Descriptors”
    • Juergen Zimmermann says:

      JPA has orm.xml, and not mapping.xml

      • agoncal says:

        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. Paulo Pires says:

    Is JPA persistence.xml good? It seems to reference java.sun.com. Can you please confirm? Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 7,477 other followers

%d bloggers like this: