users@glassfish.java.net

Re: Question on included JEE versions and packaging apps with Maven

From: <glassfish_at_javadesktop.org>
Date: Tue, 24 Aug 2010 11:57:04 PDT

If you develop a Java EE 6 application, you should try to use the official Java EE 6 API and not depend on Glassfish specific implementations. By doing so, you are able to deploy your app to any Java EE 6 compliant server - at least in theory, and currently there are very few alternatives to Glassfish.

To get hold of all Java EE 6 APIs with a single Maven dependency, you can use

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

It is important to include the scope "provided", meaning that Maven will use that dependency just for compilation but will not include it into the final product (your WAR or EAR), because it is already available in the runtime environment, i.e. the Glassfish container.

However, there is one problem with this official javaee-api.jar: you can only use it at compile time, it causes strange errors at run time since for some reason it contains some kind of mutilated byte code (more or less method signatures without bodies), so you are bound to get into trouble if you use the same Maven dependencies e.g. for integration tests.

There are some open source alternatives containing normal byte code: I recommend using the Maven artifacts in group org.apache.geronimo.specs, see

http://mvnrepository.com/artifact/org.apache.geronimo.specs

Unfortunately, there is no all-in-one dependency for Java EE 6, you have to include the individual APIs like Servlet 3.0, EJB 3.1, JPA 2.0 etc which make up Java EE 6.

I don't have a link for a complete list at hand, but I think you're on the safe side if you take the newest version of each component spec.

There is also the option of running your application and Glassfish in the same VM using Embedded Glassfish

<dependency>
  <groupId>org.glassfish.extras</groupId>
  <artifactId>glassfish-embedded-all</artifactId>
  <version>3.0.1</version>
</dependency>

This will get you all the required dependencies, but this is more appropriate for running tests than for building a WAR or EAR.

If you really want to know the exact versions of the JARs used in Glassfish, you can look at the headers in META-INF/MANIFEST.MF of the JARs in glassfish/modules, but take care not to confuse the Glassfish version (e.g. 3.0.1) with the given API version.

If you use Eclipse, you may find the following tutorial useful:
http://hwellmann.blogspot.com/2010/07/building-java-ee-6-web-application-with.html

It's about getting started with the combination of Glassfish, Maven and Eclipse (and, incidentally, Wicket).

Hope that helps,

Harald
[Message sent by forum member 'hwellmann']

http://forums.java.net/jive/thread.jspa?messageID=480904