Ejb with client artifact - runtime dependency?

Our company creates ejb in two artifacts. The impl artifact contains implementations, and the client artifact contains all interfaces. This means that the impl artifact has a compilation dependency on the client artifact.

Now, at run time, the client artifact requires an impl artifact, otherwise the container will not be able to insert the required objects. This means that the ear must contain implant artifacts for all client artifacts.

Does this mean that the client artifact must have a runtime dependency on the impl artifact. Or should these “circular” dependencies be avoided, even if one direction is compile and the other is runtime ?

+8
java dependency-injection maven dependencies
source share
2 answers

Does this mean that the client artifact should have a runtime dependency on the impl artifact?

There is no and no addiction (or it should not be better). Take a look at the import instructions in the classes and interfaces of client artifacts, and you will see that the client artifact is implementation-independent.

If the client is implementation dependent, it will violate the dependency inversion principle, which is part of the SOLID principles.

Or should these “circular” dependencies be avoided, even if one direction compiles and the other runs time?

Actually, an implementation is required at runtime, but this is a matter of building components. Maybe someone wants to replace the implementation once or for testing reasons. Therefore, it would be nice to imagine the maven dependency in a client artifact with an implementation just to simplify component layout.

Instead, you should declare the implementation dependency in the EAR deployment module, because the EAR is an enterprise application assembly.

EDIT

Our developers complain that to make sure that each client has the appropriate implant in their ear is tedious manual work. Each one looks for client artifacts in the dependency: list, adds all the relevant impl artifacts, dependency dependency: the list again, again adds all the missing artifacts, etc.

I think they perceive the role of JEE development , the phrase.

A software developer performs the following tasks to deliver an EAR file containing a Java EE application:

  • Collects the EJB JAR and WAR files created in the previous steps into a Java EE application (EAR) file

  • Specifies a Java EE application deployment descriptor (optional)

  • Verifies that the contents of the EAR file are well-formed and consistent with the Java EE specification

However, the specification also says

The assembler or deployer can edit the deployment descriptor directly or use tools that correctly add XML tags according to interactive selections.

I would say that a ear pom is an example of describing an assembly using a tool.

JF Meier also mentioned

Some developers write scripts for this process, but again, after changing the versions of some ejbs, you need to repeat the process because, perhaps somewhere deep in the dependency tree, ejb clients were deleted or added, so additional imms may be required.

For me, these scripts are the same as ear pom. Perhaps more flexible, but at the cost of standards and conventions. The fact that they have to update scripts with each version clearly shows that it would be better if these versions were also updated by maven.

Also ... Since the earpom is just a maven artifact, it can also be deployed to the repository. This is better than private scripts, which no one except the author has access to.

I hope that these arguments will help you when discussing your deployment strategy with your colleagues.

+1
source share

You do not need to worry about the implicit dependence of the client on the implementation, because the server will manage this.

The EJB container creates a proxy server through which the implementation is called, so it never directly contacts the client.

If you have a pom for EJB containing:

 <groupId>com.stackoverflow</groupId> <artifactId>Q43120825-server</artifactId> <packaging>ejb</packaging> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> </dependency> <dependency> <groupId>com.stackoverflow</groupId> <artifactId>Q43120825-api</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-ejb-plugin</artifactId> <configuration> <ejbVersion>3.2</ejbVersion> </configuration> </plugin> </plugins> </build> 

and an EAR file containing:

 <dependencies> <dependency> <groupId>com.stackoverflow</groupId> <artifactId>Q43120825-server</artifactId> <version>1.0-SNAPSHOT</version> <type>ejb</type> </dependency> <dependency> ... other modules </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.10.1</version> <configuration> <version>7</version> <defaultLibBundleDir>lib</defaultLibBundleDir> <modules> <ejbModule> <groupId>com.stackoverflow</groupId> <artifactId>Q43120825-server</artifactId> <bundleFileName>Q43120825-server.jar</bundleFileName> </ejbModule> ... other modules that might have the API jar as a dependency </modules> </configuration> </plugin> </plugins> </build> 

then this will create the correct EAR file using the jar API in it lib .

0
source share

All Articles