How to handle external jars with Maven

...the elegant way

If you've been struggling to add some jars to your maven project and maybe you've finished by adding them as a system scope dependency - you are in the right place!

After I spent some time on Stackoverflow, I decided to gather useful information and write a brief advice on how to deal with jar dependencies.

All you need to do is add and configure maven-install-plugin in your main pom.xml like this:


Then, Maven will install the configured jar in a prepare-package phase. The ${session.executionRootDirectory} variable points to the directory from which the maven command was executed.

Of course it would be better to have your own repository like Artifactory. But there isn't always such a possibility.