Maven skinnyWars does not remove ejb banks from WEB-INF \ lib \

I came across the maven skinnyWars at http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html . As described, I can use this method to move the selected dependencies from the WAR module to the EAR module. They will be available for all other WAR modules located in the EAR.

As I discovered, relocatable dependencies must be declared in the EAR module and must be included in the META-INF\lib . This does not apply to EJB modules that are located in the root directory of an EAR module.

My question is, how do I remove duplicate EJB modules from WAR and point to the links that are in the EAR file?

The structure right now looks like this:

 \-EAR -ejb.jar -META-INF\lib -shared libraries -web.war -WEB-INF\lib -ejb.jar -other non-shared libraries 
+7
source share
2 answers

I answered a similar question: How to make maven put all the banks common for wars within one EAR to the root of the EAR?

Unfortunately, this does not work for ejb modules. They will be duplicated, as you already mentioned.

One thing you can additionally use is the configuration for maven-war-plugin:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> </configuration> </plugin> 

This will completely remove everything from the WAR lib folder, but may also have its drawbacks in cases where you need to additionally deploy WAR on a separate machine without a surrounding EAR.

+2
source

The problem is that this is not the same as the EJB reference to the ear module that will be used to deploy it on the server, than to the link from the client that needs EJB classes to communicate with the server.

If you enable dependency in an ear module, it will consider that you are declaring an EJB module for deployment. It will put it in the root of the EAR and declare it in application.xml.

If you include a dependency, for example, in a military module, you will get exactly the same artifact, but it will be considered as a library and placed in WEB-INF / lib.

Now that you are generating skinny wars, explicit dependency on the ejb module makes the dependency mismatch in WAR, since Maven does not consider them the same. This causes the JAR to be stored in the WAR / s that use it.

The only thing I know is to always generate a client artifact for the ejb module, even if the client artifact is identical to the main artifact.

Now you only use the <type>ejb</type> dependency in the EAR. For clients, you always use <type>ejb-client</type> .

To remove a client from WAR / s and find it in the lib EAR directory, you must explicitly add the dependency to the ear module.

So, you will have two dependencies to the ejb module in your ear module: one to ejb itself and one to the client. The first will put the EJB in the root of the EAR and declare it in application.xml. The second will put the client in the lib EAR directory and update WAR / s manifest / s if necessary.

But if the client and the main artifacts are identical, can you duplicate it?

The short answer is yes. The long answer is yes. It is duplicated, but only once, and not in every WAR that uses it. I do not think that there is a pure way to avoid this, and I am not sure if this makes sense conceptually. Of course, you can use packageExcludes and customize manifests, but it makes sense to have a JAR twice.

If your JAR client is really thinner (for example, only interfaces) that have a WAR / s link, the client JAR effectively denies them access to EJB implementations, which is always a good idea.

You can consider an identical JAR as a special case of the previous one, and it makes a conceptual meaning to keep them separate.

So, my recommendation is to always generate a client artifact for ejb and act as explained. There are always things that you can exclude from it, at least any unnecessary files without a class, such as package.html or ejb-jar.xml.

+1
source

All Articles