4

If you declare a dependency in Maven, you can add a type, like war, jar, ejb.

I understand that compiling a project with type ejb is different from compiling a project with type jar because it triggers a different lifecycle.

But what is the difference in declaring a dependency?

Maven dependency type ejb vs jar seems to ask the same question, but the accepted answer seems strange to me. I doubt that a type in a dependency can trigger a lifecycle. Actually, I would expect that type ejb and type jar do exactly the same thing. Can somebody shed light on this?

Community
  • 1
  • 1
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • 1
    Maybe more thoughts can be added, but yes, they should behave in exactly the same way, and only differ for "documentation" purposes ([peek at the source code of maven-aether-provider for example](https://github.com/apache/maven/blob/maven-3.3.9/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemUtils.java#L115-L116)). A different lifecycle is launched when you have a project with packaging EJB i.e. `ejb`, not a dependency on a EJB. – Tunaki Dec 01 '16 at 16:12
  • There is no accepted answer in your linked topic. – Chris311 Jan 07 '19 at 12:37

1 Answers1

0

I doubt that a type in a dependency can trigger a lifecycle

You are not alone to doubt.

When you declare a dependency with the ejb type, you benefit from some facilities provided by Maven related to ejb as :

  • the ability to add the declaration of the EJB in the application.xml. Since Java EE 5, it is not required any longer.

  • the check that the dependency is a EJB and not a simple JAR.

  • and probably some other minor things.

You would have not these facilities if you declare your dependency with the jar type.

As you can notice, it doesn't change at a lot of thing but anyway, in both cases, it is the same JAR which is used for the dependency.

You don't refer to the ejb-client type but it is often something of more interesting since contrary to the case of the dependency with the jar or ejb type which uses the same jar, when you declare ejb-client type in a dependency, you depend on a different jar that the classic jar since this jar should contain only API classes to call the ejb.
Of course, if we want the version ejb-client of our ejb, we have to specify it in the artifact which produces the ejb.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • 1
    In JBoss EAP 7 I noticed that packaging type ejb may be needed for dependency injection. JBoss could not find an EJB (ie Singleton) in a jar packaged module (or external jar dependency). It required package-ejb and dependency type ejb for that to work. – Merijn Vogel Jun 18 '19 at 13:25