0 Replies Latest reply on Aug 25, 2013 5:07 AM by agoncal

    How to choose which Java EE version ?

    agoncal

      Hi all,

       

      Java EE 7 is out... and one day will come Java EE 8, 9 and so on. So we should be able to ask JBoss Forge to either generate a Java EE 6 or 7 application... and if we want to be more precise, you could even go into choosing from Java EE 6, Web Profile 6, Java EE 7 and a Web Profile 7 application. But how to choose a version with JBoss Forge ?

       

      Today, with JBoss Forge 1.x, you create a project with a CLI without giving any version indication :

       

      new-project --named app1 --topLevelPackage org.app1 --type war
      

       

      Then, when you setup your project, you give Forge some hints :

       

      persistence setup --provider ECLIPSELINK --container GLASSFISH_3 --named testPU ;
      validation setup --provider HIBERNATE_VALIDATOR ;
      

       

      If the idea is to use Forge to create Java EE applications running in a container (and not just in standalone Java SE), the CLI to create a project misses some information, and the setup is redundant. I would think of something like :

       

      new-project --named app1 (...) --version JAVAEE_7 --container GLASSFISH
      new-project --named app1 (...) --version JAVAEE_6 --container GLASSFISH
      new-project --named app1 (...) --version JAVAEE_WEBPROFILE_6 --container GLASSFISH
      new-project --named app1 (...) --version JAVAEE_WEBPROFILE_7 --container GLASSFISH
      

       

      Note that I didn't put the version of GlassFish because the version of Java EE implies the version of GlassFish (eg. Java EE 6 == GlassFish 3, Java EE 7 == GlassFish 4). But note that you could also specify the container if needed (e.g. generate a Java EE 6 app running on GlassFish 4)

       

      new-project --named app1 (...) --version JAVAEE_6 --container GLASSFISH_4

       

      And, of course, the following would be illegal (GF 3 cannot run a Java EE 7 app) :

       

      new-project --named app1 (...) --version JAVAEE_7 --container GLASSFISH_3
      

       

      On this comment, Lincoln says that the application should only depend on Java EE APIs. So I think the pom.xml should only contain one of the following dependency (depending on the version of Java EE 7) :

       

      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
      </dependency>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
      </dependency>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
      </dependency>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
      </dependency>
      

       

      You do not need any extra dependency if you want an application to depend only on Java EE. So that means the following commands can also be changed from :

       

      persistence setup --provider ECLIPSELINK --container GLASSFISH_3 --named testPU ;
      validation setup --provider HIBERNATE_VALIDATOR ;
      

       

      to

       

      persistence setup --named testPU ;
      validation setup ;
      

       

      No need to specify the provider. That's because you will use the JPA/Bean Validation/... default implementation of the container (GlassFish uses EclipseLink, JBoss uses Hibernate...). And to ease the configuration and portability, this means that you don't need the <provider> element in the persistence.xml :

       

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="javaone2013PU" transaction-type="JTA">
          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
          (...)
        </persistence-unit>
      </persistence>
      

       

      Nor do you use the <default-provider> element in the validation.xml (and so on).

       

      I think the Java EE version should be specified when the project is created, and then all the setups would use the default container implementation.