1

I followed some tutorials on EJB 3.1 and those were using the following dependency for EJB-API.

    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.1_spec</artifactId>
        <version>1.0.2.Final</version>
    </dependency>

My problem is, this is only for jboss or can I used this in any other application servers. If not why there are dependency like these which are not independent from the application server it gets deployed. And also I found this reference for ejb 3.1 api. Therefore please elaborate what are these and why those are there.

Community
  • 1
  • 1
Isuru Gunawardana
  • 2,847
  • 6
  • 28
  • 60

2 Answers2

2

Here you go. This is from EJB specs.

<dependency>
    <groupId>javax.ejb</groupId>
    <artifactId>javax.ejb-api</artifactId>
    <version>3.2</version>
</dependency>

Hope this helps.

David Newcomb
  • 10,639
  • 3
  • 49
  • 62
  • This is ok, What I am asking is the above mentioned dependency is only for jboss servers? Can't we deployed an ear which is bundled with that dependency in any other application server other than jboss? – Isuru Gunawardana Mar 12 '15 at 05:07
  • 2
    An API is usually not bundled in the ear. This kind of dependency is usually `provided` which means it can be found in the target environment (within the application server). – khmarbaise Mar 12 '15 at 07:41
  • @khmarbaise, So what do you mean is `javax.ejb-api` the api and `jboss-ejb-api_3.1_spec` is an implementation of that? And if we are writing an application which is to be deployed on two different application servers (jboss & websphere) what should mentioned in the pom is `api` (in this case `javax.ejb-api` ) with `scope` as `provided`. Am I right? – Isuru Gunawardana Mar 12 '15 at 08:20
2

You can use it on any server you like. Just remember to put add the <scope>provided</scope> tag to the dependency like this:

<dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.1_spec</artifactId>
        <version>1.0.2.Final</version>
        <scope>provided</scope>
</dependency>

The provided scope means that this dependency is only used to compile your code and not included in the resulting EAR/WAR/JAR. In the runtime this dependency is provided by your application server (JBoss, Websphere, whatever). If you omit the scope specification section very bad things may happen.

Kamil Roman
  • 973
  • 5
  • 15
  • 30
  • One thing to clarify, is `javax.ejb-api` the api and `jboss-ejb-api_3.1_spec` is an implementation of that? And if we are writing an application which is to be deployed on two different application servers (jboss & websphere) can we also mention only the `api` in the pom (in this case javax.ejb-api ) with scope as `provided` and it makes the server to use its own implementation when running? – Isuru Gunawardana Mar 12 '15 at 12:15
  • 1
    It is the api (interfaces) and not the implementation. Server will try to use its own implementation anyway, however, if you omit the provided scope specification, 2 implementations will be on the classpath and it is random, which one will be used. What's more, AFAIK the javax.ejb spec contains some crippled classes without class body which means that your code may simply crash, either regularly or at random. And yes, if you mention only the api in the pom as provided the server will use its own implementation when running – Kamil Roman Mar 12 '15 at 12:30
  • Thanks for the reply, but I have a problem, can we use only the `api` to compile the code with out specifying any `implementation`? – Isuru Gunawardana Mar 12 '15 at 12:51
  • 1
    Exactly so. The real implementation will be provided by the application server at runtime. – Kamil Roman Mar 12 '15 at 13:33