20

I know this has been asked a million times and I did do my homework, but the one last thing I don't fully understand is, is there a "Java EE JDK" ?

When I download the SDK, it tries to install lots of crap I don't want. So I did some reading and realized that actually the Java SDK is a set of tools technically unrelated to the JDK. So what I am looking for is a clean simple standalone download of the JDK only.

We know that "Java SE JDK" has always been available from Sun's (now Oracle) website. However, I am developing a web application and interested in some of the Java EE features: javax.servlet, javax.validation, javax.persistence and javax.transaction. So in effect what I'm really looking for is a "Java EE JDK".

I'm using a typical Maven / Tomcat / Spring / Hibernate setup and in the past I've always added API-only dependencies in provided scope in Maven to my project for these parts of the Java EE specification, i.e:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

So if I do this for all the Java EE APIs that my project requires, then I am actually using Java SE JDK with some additional manually-declared Java EE components. Furthermore when I direct my IDE to use the JDK that came with the Java EE SDK installation, these additional namespaces aren't available.

In other words, for all intents and purposes it would appear that the JDK that comes with the Java EE SDK download is equivalent to the JDK that I get when I install the "Java SE JDK"... If this is correct then there is no need for me to install the Java EE SDK and I can simply use the Java (SE) JDK declaring any Java EE components that I need as *-api/provided dependencies the way I described above.

So my questions is: is what I describe above the right way to go, or is there such a thing as a "Java EE JDK"? i.e a JDK that comes with the unimplemented interfaces of things like javax.servlet and javax.resources and so on? And if such a beast exists, where would I download it from?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Amir Abiri
  • 8,847
  • 11
  • 41
  • 57

3 Answers3

20

What you're asking is "can I get all the EE components" as a single download without GlassFish, NetBeans, etc.

Well it's helpful to know exactly what Java EE really is. It's a set of specifications of sometimes related / sometimes unrelated "Enterprise" level components (whatever Enterprise means :)). For example, the servlet-api spec (as indicated by a previous answer) is part of the Java EE spec. So is the JTA (transaction API), JPA, Java Mail, and so on.

There are two types of EE component. 1. Those which are shipped as interfaces only and the application-server or a third party implements them. Examples are JTA, JPA, Servlet-API. 2. Those which are shipped as full reference implementations. Examples are Java-Mail. I can't think of others off top of my head but there will be some.

Now a full application server, such as glassfish, ships with the set of implementations so lots of times people see them inside Glassfish, Websphere etc and think that they need that to use them. A container such as Tomcat is not an application server, it is a servlet-container and thus only implements a subset of the full Java EE stack (the parts that are required for servlets only).

In order to get the full set of Java EE interfaces/implementations you would need to add the separate interfaces or implementations to your build. In that case you just "have to know" where to find them, and that comes by experience. People tend to know that JPA is added as part of the Hibernate dependencies for example.

sksamuel
  • 16,154
  • 8
  • 60
  • 108
5

When it comes to downloading the JDK, there is only one JDK, whether you get it from the Java SE downloads or from the Java EE downloads.

The difference is that when you download it from the Java EE downloads, it is packed in in a SDK. The SDK comes with Glassfish, Code Samples, API Documentation, Tutorials. I don't really need these so I prefer downloading from the Java SE downloads.

In a Maven JavaEE project you would specify your dependencies to the Java EE libraries. In the case of jboss AS7, you use the jboss-spec dependencies that will let you do imports for all the Java EE classes. It is up the Application Server to provide the classes that implement the Java EE APIs:

<dependency>
   <groupId>org.jboss.spec</groupId>
   <artifactId>jboss-javaee-6.0</artifactId>
   <version>3.0.2.Final-redhat-3</version>
   <type>pom</type>
   <scope>import</scope>
</dependency>

If you want to see the javaEE artifacts imported by this pom, take a look at: http://maven.repository.redhat.com/techpreview/eap6/6.1.0/maven-repository/org/jboss/spec/jboss-javaee-6.0/3.0.2.Final-redhat-3/jboss-javaee-6.0-3.0.2.Final-redhat-3.pom

Miguel Reyes
  • 2,444
  • 1
  • 21
  • 11
2

Generally, you're more or less correct.

The application servers usually ship the Java EE API as well as the implementation of the Java EE API. So in case you want to use the same version as your application server then use:

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.5</version><!-- or whatever version your application server provides -->
   <scope>provided</scope>
</dependency>

If you want to use a newer version you should omit the provided scope.

If you want to use a newer or a different implementation (e.g. EclipseLink instead of Hibernate) you have to add a dependency for the implementation as well. Otherwise you can omit it.

Puce
  • 37,247
  • 13
  • 80
  • 152
  • 2
    I forgot to use provided in my example but that's what I always do in practice. In regards to my main question ("is there a Java EE JDK?") your answer is "no", there is a Java JDK and there are Java EE APIs and the interfaces of the Java EE APIs are distributed separately to the Java JDK, either with distributions of implementations, or as api-declaration-only distributions. Am I understanding this correctly? – Amir Abiri May 03 '12 at 20:15
  • 1
    @AmirAbiri yes, that's correct – Puce May 03 '12 at 20:21