DEV Community

Marcos Henrique
Marcos Henrique

Posted on

9 2

Adding local jar files to a Maven project

I was developing a project with spring and maven, however when performing the build I came across a strange error



org.springframework.beans.factory.unsatisfieddependencyexception error creating bean with name 


Enter fullscreen mode Exit fullscreen mode

Even though my jar is in the build path, the error persisted, I tried to install it with the java -cp of life, but the problem persisted, that's when I tried something a little different, directly add the dependency in pom.xml, after all it is an abstraction of the manifest in spring application

Solution

There are many ways to add local jar files to a Maven project:

  • Install manually the JAR into a local Maven repository use this command: ```bash

mvn install:install-file –Dfile=C:\dev\app.jar -DgroupId=com.mh.tutorial-DartifactId=my-example-app -Dversion=1.0

Now, add the dependency to your Maven project by adding these lines to your **pom.xml** file:
```xml


<dependency>
    <groupId>com.mh.tutorial</groupId>
    <artifactId>my-example-app</artifactId>
    <version>1.0</version>
</dependency>


Enter fullscreen mode Exit fullscreen mode
  • Adding directly the dependency as system scope Consider that the JAR is located in <PROJECT_ROOT_FOLDER>/lib. After this add the dependency in your pom.xml file as following: ```xml


com.mh.tutorial

<artifactId>my-example-app</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/myCustomJAR.jar</systemPath>
Enter fullscreen mode Exit fullscreen mode

![](https://media1.giphy.com/media/6PopYBwOlKS8o/giphy.gif?cid=790b76113605f90875a8ba21a11cefe9e5a7351de1509bc0&rid=giphy.gif)
Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
khmarbaise profile image
Karl Heinz Marbaise

I have to mentioned that the system scope will produce a WARNING since Maven 3.5.2 furthermore if you use a system scope dependency it will become hard for consumers of your project cause they don't have the directory nor the jar on their hard drive which results in failures. That means in other words you should prevent using system scope under all circumstances cause it will cause many issues.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay