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

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

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.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️