Student of Life

Upgrading To The Java EE 6 Web Profile

By , 21 March 2012

Upgrading To The Java EE 6 Web Profile
Upgrading To The Java EE 6 Web Profile

Here are my notes from our upgrade of the Sunburnt SEO software to the Java EE 6 Web Profile. Previously our stack was pretty similar to Java Web Profile, just with a lot more dependencies than is now necessary with EE 6.

We can now deploy to Glassfish 3.1 or a modified Tomcat 7.0, since we aren't using the EJB features of Java EE 6.

Code Changes

persistence.xml is now version 2.0

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
             http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

web.xml is now version 3.0

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
         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/web-app_3_0.xsd">

Remove vendor-specific JPA annotations.

  • //@Index
  • //@ForeignKey
  • //@ElementForeignKey
  • //@ContainerTable
  • //@PersistentMap
  • //import org.apache.openjpa
Upgrading To The Java EE 6 Web Profile

Issues

[1] Missing API Code

Bytecode enhancement fails with OpenJPA and EclipseLink because of the default API jars missing code. This also affects JSF.

The workaround is to change the pom.xml dependency to

    <!-- default Jave EE jars don't include code necessary fo
         bytecode enhancement so we use these instead -->
    <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>1.0.0.Final</version>
      <scope>provided</scope>
      <type>pom</type>
    </dependency>

[2] EL expressions throw an exception

Passing bean references by EL fails when they are dereferenced. This is a known bug.

Adding this to the pom.xml "fixes" the problem.

    <!-- default Glassfish EL is broken
         http://java.net/jira/browse/JAVASERVERFACES-1828 -->
    <dependency>
      <groupId>com.sun.el</groupId>
      <artifactId>el-ri</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
    </dependency>

[3] Multipart Forms Fail Silently

commons-upload doesn't work with Servlet-3.0, but the Servlet-3.0 Multipart API is almost identical so it is easy to replace. Tomcat needs

<Context path="" allowCasualMultipartParsing="true">

since we cannot add the @MultipartConfig tag to the Faces Servlet and <multipart-config/> in web.xml doesn't seem to work. Glassfish does not seem to need this configuration.

[4] Glassfish EL Calls Incorrect Method

EL 2.2 doesn't seem to distinguish between methods like getItem(String url) and getItem(Long id) which used to work with JBoss EL. I just changed the method names to fix this.

They are the main problems we hit. Hopefully these links will help you out upgrading your app.

 

About Roger Keays

Upgrading To The Java EE 6 Web Profile

I am an artist, an engineer, and a student of life. Some projects I'm working on at the moment are The Game Of Your Life, Memory Genius and Money Talks. I write every Sunday about travel, psychology and technology. Click here to subscribe, or follow me via RSSTwitter, Facebook, and even Google+.

Add a comment

Please visit https://RogerKeays.com/upgrading-to-the-java-ee-6-web-profile to add your comments.

Follow Roger Keays

Join the Mailing List

Subscribe to our mailing list for the latest news and announcements.


It'll Change Your Life

I write every Sunday about travel, psychology, and technology. Drop me your email and you'll be the first to get my articles when they're published. It'll change your life. And it's free :)


Website Updates

Latest Poll

Chocolate or avocados?
Chocolate
Avocados