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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

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

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay