Include jar file in Maven project


How do I include a single .jar in a Maven project?


The jar I need to include has dependency on 3 other jar files.

The jars in question are from the project Brunette

Attempt # 1

I created a lib directory and put the jar there.

I added the dependency in the POM:


When building:


Some problems were encountered while building the effective model for   MyPackage: MyProject: jar: 1.0 'dependencies.dependency.systemPath' for   abc: abc: jar should not point at files within the project directory,   $ {basedir} /lib/morena7.jar will be unresolvable by dependent projects   @ line 30, column 25

At runtime, java.lang.NoClassDefFoundError occurs

asked by anonymous 02.07.2014 / 16:18

1 answer


There are several ways to resolve this.

Keeping your repository

The ideal is to install the jars in a repository of your company / house. For this you need a server with Artifactory or Nexus .

The advantage of having your own repository is that you can use it to manage the versions of your projects as well.

Another advantage is that it caches the central repository and its environment gets faster.

Dependencies with scope system

You can also point to the dependency path of type system . Consider the following example:


These dependencies may also be within the project. Use the ${basedir} variable to indicate the project home directory.

The problem with this approach is that you need to keep the Jars in the repository, which is not very suitable.

See the documentation for more details.

Note: Maven has added a restriction on the use of libs within the project, as can be seen in the error edited in the question. You should then use a directory outside the project.

Installing dependencies in the local repository

Another solution is to use the install plugin to install the jars in a local repository. This can be done with the mvn install:install-file command and the appropriate parameters. See documentation for more details.


mvn install:install-file -Dfile=morena7.jar -DgroupId=sk.gnome \
    -DartifactId=morena -Dversion=7.0 -Dpackaging=jar

Please note that the above data was invented and will only work in the environment in which it was installed.

The problem with this approach is that the installation process needs to be repeated in each environment, that is, on each development machine and on the Continuous Integration server, if any.

02.07.2014 / 17:54