How to package a jar-with-dependencies with maven and not to die trying!



How to package a jar-with-dependencies with maven and how to manage resource collisions (if we have multiple log4j.xml for example).

Sometimes it's easier to distribute our application in a single fat jar (myapp-1.0-jar-with-dependencies.jar) instead of distributing our jar + libs.jar. To achieve this, we can use maven-assembly-plugin and the jar-with-dependencies descriptor.

However, the jar-with-dependencies works but until we have resource collisions. Imagine that you have your own /src/main/resources/log4.xml but one of your dependencies (i.e. dependency.jar) has a /log4j.xml as well.

To handle this situation, we can redefine the jar-with-dependencies assembly descriptor so we start packing the fat jar first with our own project files and then include the rest of the dependencies. That will work because maven will not overwrite files that already exists.

Another thing to keep in mind, is that it works fine for any resource, except for the MANIFEST.MF file that is handled by the maven archiver-plugin. In that case, we must redefine the manifest configuration in the maven-assembly-plugin.

Here is the configuration you need to package your own myapp-1.0.0-jar-with-dependencies.jar with your own log4j and MANIFEST and not die trying:
And here is the src/main/assembly/jar-with-dependencies:xml:

Comments

  1. Merkur 37C Safety Razor Review – Merkur 37C
    The Merkur 37c is an excellent short handled DE safety razor. It 메이피로출장마사지 is more suitable for both https://deccasino.com/review/merit-casino/ heavy and non-slip poormansguidetocasinogambling hands and is therefore a great option for 토토 사이트 experienced 바카라 사이트

    ReplyDelete
  2. With all the advantages of|some great advantages of|the advantages of} the digital on line casino, there are some things that need improvement. For instance, the shortage of 24/7 chat help could make 온라인카지노 some gamers cautious when a query wants a direct answer. There additionally be|can be} an absence of telephone contact with the net casino’s help team.

    ReplyDelete

Post a Comment

Popular posts from this blog

Java 9 Process API

Android 3D Model Viewer Open Source

How to build a replicated ehcache through firewall and not to die trying