Java EE 7 Deployment Descriptors
Join the DZone community and get the full member experience.
Join For FreeAs 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 blog “It’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>
constraints.xml
<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 338) persistence.xml files introduces new standard properties for schema generation (more on that in a coming post).
Persistance.xml
<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://java.sun.com/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> </persistence>
Mapping.xml
<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>
aJSFPage.xhtml
<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…)).
Published at DZone with permission of Antonio Goncalves, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
-
What Is JHipster?
-
WireMock: The Ridiculously Easy Way (For Spring Microservices)
-
The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables
Comments