11

What is the difference between

    <dependency>
        <groupId>groupId</groupId>
        <artifactId>artifactId</artifactId>
        <type>ejb</type>
    </dependency>

and

    <dependency>
        <groupId>groupId</groupId>
        <artifactId>artifactId</artifactId>
        <type>jar</type>
    </dependency>
Chris311
  • 3,794
  • 9
  • 46
  • 80
  • 1
    An `ejb` type is generated by [maven-ejb-plugin](https://maven.apache.org/plugins/maven-ejb-plugin/) and the intention is that this is an EJB which is used in relationship with an EE application. – khmarbaise Feb 16 '16 at 08:27
  • 2
    @khmarbaise: And what if I use jar? Isn't this possible for an EE application as well? – Chris311 Feb 16 '16 at 08:29

4 Answers4

2

Maven will trigger a different lifecycle, depending on the packaging. See here for a list of bundled lifecycles.

In your particular case, the difference will be that, instead of calling the jar:jar goal during the package phase when using jar as packaging, it will trigger the ejb:ejb one, capable of handling specific tasks related to an EJB module (client generation...).

Tome
  • 3,234
  • 3
  • 33
  • 36
  • And when do I have to use one or the other? – Chris311 Feb 16 '16 at 11:34
  • It really depends on the purpose of your module. You can see the `maven-ejb-plugin` as a specialized `maven-jar-plugin`; if you do need one of the special treatment the `maven-ejb-plugin` provides (check the plugin site - https://maven.apache.org/plugins/maven-ejb-plugin/ - for more info), you'd better use the ejb packaging. If not (for instance when using EJB spec 3+), you might just use the `maven-jar-plugin`, so keep the default packaging. – Tome Feb 16 '16 at 12:18
  • `maven-ejb-plugin` will have to be used if you need some specific 'EJB' capabilities for your Maven module, such as generating an EJB client, specifying the EJB version to use... (see https://maven.apache.org/plugins/maven-ejb-plugin/usage.html) – Tome Dec 18 '17 at 22:30
  • AFAIK, this does not answer the question (ejb type of a dependency). This answer is more about the ejb packaging – Puce Jan 01 '19 at 20:13
  • @Tome The question talks of dependency type and not project type – Number945 Dec 05 '19 at 12:23
0

As the ejb is the main artifact generated by the maven-ejb-plugin and since it's a JAR artifact, it doesn't really matter if you're you using the ejb type or use the (default) jar type when specifying a dependency, AFAIK. (Similar to OSGi bundles, which sometimes also are created with the bundle packaging, but are just JAR files).

If you want to add a dependency to a secondary artifact (e.g. ejb-client, test-jar) or if the dependency has a different file extension, then you have to specify the type or the classifier.

The documentation seems to prefer to use the ejb type, but it also produces some noise and is sometimes slightly less maintainable to specify the ejb type everywhere. It is a very strict approach.

Puce
  • 37,247
  • 13
  • 80
  • 152
0

<type>ejb</type> is needed when your artifact artifactId has EJBs and you want to use them. If you don't need the EJBs in your module <type>jar</type> is an option.

Chris311
  • 3,794
  • 9
  • 46
  • 80
-2

If you dont specify any type in your dependency, it will select default type as "jar" which means look for a file with jar extension on any remote/local repository. When you specify any other type like "ejb", "so", "aar" maven will look for file with this extension.

Fuat Coşkun
  • 1,045
  • 8
  • 18
  • 1
    At the moment I got type ejb but I can't find an artifact with file extension ".ejb" in my ear. There is only a "artifactId.jar". – Chris311 Feb 16 '16 at 08:36