davioooh
davioooh

Reputation: 24696

Configure local jar in pom.xml

In my maven project I need to use some local jar libraries as a dependency.

I'm trying to use this method to configure them in pom.xml:

<repositories>
    <repository>
        <id>projectName.local</id>
        <url>file://${project.basedir}/libs</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.myproject</groupId>
        <artifactId>ProjectName</artifactId>
        <version>1.0</version>
    </dependency>

    <!-- other dependencies... -->
</dependencies>

I defined a local repository that points to a libs folder into the project root. Then I placed the jars in this folder:

/libs/org/myproject/ProjectName/1.0/ProjectName-1.0.jar

But, building the project I'm getting this warning:

The POM for org.myproject:ProjectName:jar:1.0 is missing, no dependency information available

And this build failure result:

Failed to execute goal on project my_project: Could not resolve dependencies for project *** : The following artifacts could not be resolved: org.myproject:ProjectName:jar:1.0: Failure to find org.myproject:ProjectName:jar:1.0 in file://C:\Users\David\Documents\NetBeansProjects\my_project/libs was cached in the local repository, resolution will not be reattempted until the update interval of projectName.local has elapsed or updates are forced -> [Help 1]

What am I missing?

Upvotes: 4

Views: 9068

Answers (3)

Nitin Pawar
Nitin Pawar

Reputation: 936

You can add your local jar as:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

Local works for you by doing above.If you want to pack this local jar in your fat jar then include following line in maven plugin configuration:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <includeSystemScope>true</includeSystemScope>
  </configuration>
</plugin>

Upvotes: 2

gil.fernandes
gil.fernandes

Reputation: 14611

I think just copying the jar file will not solve your problem. You will need to install the dependency using Maven itself in that repository using a command like this one:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file  -Dfile=path-to-your-artifact-jar \
                -DgroupId=your.groupId \
                -DartifactId=your-artifactId \
                -Dversion=version \
                -Dpackaging=jar \
                -DlocalRepositoryPath=path-to-specific-local-repo

path-to-specific-local-repo should be the path to your local repository (file://${project.basedir}/libs).

Upvotes: 3

Raja Ramachandran
Raja Ramachandran

Reputation: 456

        Define the pom.xml like dependency.

                  <dependency>
                    <groupId>org.myproject</groupId>
                    <artifactId>ProjectName</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <scope>system</scope>
                    <systemPath>${project.basedir}/src/main/resources/jarfile</systemPath>
                </dependency>

      Put the all the files in the folder

Upvotes: 1

Related Questions