Maven: javaee-api vs jboss-javaee-6.0

2020-02-10 15:14发布

问题:

I want a Java JEE6 project built with maven, and I want it standard

So, I put this in my pom.xml:

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

A project like this, it is supposed to run in every JEE6 container compatible (jboss, geronimo, glashfish, etc.)

Then, why this jboss dependency exists?

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-6.0</artifactId>
    <version>3.0.2.Final</version>
    <scope>provided</scope>
 </dependency>

If I use it, am I tied to jboss so I can only use this server with this application?

Is it not preferable to always use the standard javaee-api?

Thank you!

回答1:

The standard api is crippled, i. e. method bodies are missing. This turns out when testing. I have once run into this pitfall and was not very happy with it.

Therefore it is advisiable to use another package as reference.

You can have a closer look on Adam Biens Blog

You can also make profiles for different deployment environments if you really need. However, essentially I agree, this is sadly not a very pleasant circumstance.

For having issues with testing, you can have a look at this thread.

Edit:
By the way, since now this might be interessting. This issue is gone for the javaee-(web-)api for Java EE 7 (source)



回答2:

The first solution with java-api dependence is the right way: your application in ideal case should not be cared about server environment under what it works. For unit test you can use Arquillian, which helps you to test enterprise beans at "home" without headache. If you are using jboss-javaee, are you sure, that your application will deployed and work fine on another server, than jboss?