Maven ejb client generation dependency exception

We have a solution in which our user interface projects include quite a few business services using EJB client dependencies. The problem with this on Maven is that although the .jar client usually contains about 1-2 classes, they bring with them a complete dependency stack of the entire service application. It can become a little ugly when .ear files start to grow up to 50-100 MB of pop music, and from time to time inhibited errors appear due to irrelevant dependencies that make their way into the user interface application.

Of course, we can always eliminate dependencies on the client side, but then we need to write the same set of lines for each client project using these services and a lot of unnecessary repetition. In addition, people come up with the strangest error messages and use a lot of time to track them before recalling that they turned on some client bank and did not check what additional dependencies it makes to the equation.

Example:

<dependency> <groupId>fi.path.to.service</groupId> <artifactId>customermanagement-common</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>fi.path.to.service</groupId> <artifactId>customermanagement-service</artifactId> <classifier>client</classifier> <exclusions> <exclusion> <groupId>fi.path.to.dependency</groupId> <artifactId>internal-dependency-#1</artifactId> </exclusion> <exclusion> <groupId>org.codehaus.castor</groupId> <artifactId>castor</artifactId> </exclusion> <exclusion> <groupId>fi.path.to.dependency</groupId> <artifactId>internal-dependency-#2</artifactId> </exclusion> <exclusion> <artifactId>internal-dependency-#3</artifactId> <groupId>fi.path.to.dependency</groupId> </exclusion> <exclusion> <artifactId>internal-dependency-#4</artifactId> <groupId>fi.path.to.dependency</groupId> </exclusion> <exclusion> <artifactId>internal-dependency-#5</artifactId> <groupId>fi.path.to.dependency</groupId> </exclusion> <exclusion> <artifactId>castor-xml</artifactId> <groupId>org.codehaus.castor</groupId> </exclusion> <exclusion> <artifactId>castor-codegen</artifactId> <groupId>org.codehaus.castor</groupId> </exclusion> <exclusion> <artifactId>castor-xml-schema</artifactId> <groupId>org.codehaus.castor</groupId> </exclusion> <exclusion> <artifactId>internal-dependency-#6</artifactId> <groupId>fi.path.to.dependency</groupId> </exclusion> </exclusions> <version>2.6</version> </dependency> 

This is just one service client, which includes, imagine that you have several of them in several different applications, and you get an image, recording all the exceptions, every time itโ€™s very annoying, and the POM of the project starts for a rather long time.

I would note the dependency as provided, but there are two dependencies that lead to runtime failure if they do not exist. Tell those that include another service call to another application with an external Exception class that for one reason or another has not completed inside the service project and will throw a ClassNotFoundException at runtime if not present.

Therefore, I know that it is possible to exclude / include classes from the ejb client during its generation by using the pom.xml specifications in the maven-ejb-plugin, but is there a way to exclude dependencies?

+6
source share
2 answers

It seems that Maven just doesn't support building multiple jars from the same module very well.

Thus, the only reasonable way that we found is to create another module (interrupt the xxx service to the xxx service and xxx-service-client) and configure the xxx-service-client module to have only the EJB client / delegate and minimal dependencies . Thus, a project can be built with one execution.

+1
source

I have the same problem. I think one solution can use profiles, because in each profile you can specify dependencies (see http://blog.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-project -and-why-you-shouldnt / )

In my case, this does not work, because I need to create both JARs (ejb and ejb-client) in one Maven run. :)

0
source

Source: https://habr.com/ru/post/920101/


All Articles