Skip to content

Maven: best way of linking custom external JAR to my project?

It’s my first couple of days learning Maven and I’m still struggling with the basics. I have an external .jar file (not available in the public repos) that I need to reference in my project and I’m trying to figure out what my best option is.

It’s a small scale project without a central repository for libraries, so it has to be either a local repository (somehow added to source control, don’t know if it’s supposed to work that way?) or the .jar needs to be stored on disk outside of any formal repository.

1) What’s my best option for adding the .jar file to my project’s references with maven given that I want both the project and the library to be in source control?

2) I still can’t seem to have Eclipse see the dependency. I manually added it to the section of the pom, and it shows up fine in the Dependencies list in m2eclipse. mvn compile and mvn package both succeed, but running the program results in:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
        LibraryStuff cannot be resolved to a type

This is after editing the POM as:


Should I be executing mvn install:install-file even thought I already have the pom.xml edited as above?




I think you should use mvn install:install-file to populate your local repository with the library jars then you should change the scope from system to compile.

If you are starting with maven I suggest to use maven directly not IDE plugins as it adds an extra layer of complexity.

As for the error, do you put the required jars on your classpath? If you are using types from the library, you need to have access to it in the runtime as well. This has nothing to do with maven itself.

I don’t understand why you want to put the library to source control – it is for sources code not binary jars.