How to add external libraries in Maven

While I was working on dropbox writer, I run into this problem. I have a maven based project that to use dropbox java SDK, but dropbox java SDK is not in any well known Maven repository. So I did some research on add dropbox sdk dependency to maven. After two days of trial and erros I’ve found a few ways to approach this.

First thing I found was to add system path property under dependency configuration, but this solution excludes the library from maven build.

Also I found people suggest that I should create my own maven repository. If you are interested this blogs have details on how to create maven repository in github. While this is a workable solution, I don’t really want to maintain a dedicated maven repository.

The best solution I found was to create an in project repository. The idea is your will create a library folder inside your project. You’ll configure your pom to point to the repository and it will act as a normal maven repository.

To get started first you need to create a library folder under your project, I’ll call this folder libs (make sure it’s in the same folder as your pom). Then you create a sub folder structure under libs and name your library using the following convention.

I’ve created the following structure for dropbox sdk library

groupId = dropbox
artifactId = dropbox-sdk
version = 1.3.1
the library file = dropbox-sdk-1.3.1.jar

Next open your pom.xml and add the following block under repositories

This will point to you in project repository. The name field can be anything.

Now in the pom.xml you can add dropbox dependency as following

Notice the groupId, artificatId and verion follows the pattern described above.

You can add multiple dependencies by creating them in separate folder structure under libs.