July 16, 2012

Using local jars in a maven project

Maven is great, really, but sometimes you just have to use that obscure jar library that isn’t in any maven repository. You know, not everyone uses maven.

So, how do you handle this type of dependencies? This is what I do, and you might find it useful: I create a local repository within the project. This way you can put everything in you version control system, and have maven deal with everything. Also, if you have several subprojects using the same library, you can create the local repository in the toplevel.

OK. Sounds good, right? Here’s how I do it:

  1. Create a directory under the project. I always use “lib”
  2. Install the jar libs to this directory using:
    $ mvn install:install-file -Dfile=<jar_file>  -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=jar -DlocalRepositoryPath=<path_to_lib_dir>
  3. Add the repository to you POM file:
    <repositories>
        <repository>
            <id>lib</id>
            <url>file://${project.basedir}/lib</url>
        </repository>
    </repositories>
    
  4. Add the dependencies for whatever jars you’ve added to your local repo
  5. Joy.

And that’s it. If you want to share a different solution, please do.

One Comment

  1. Gustavo Oliva %A %B %e%q, %Y at %I:%M %p

    Me ajudou! :-)

Leave a Comment