Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add jar to the maven local repository before build

Tags:

java

maven

i have third part jar file which doesn't exist remotely the file located inside the project directory , i want to add this jar into the local repository when i execute mvn install, my current code for doing that

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>install-file</goal>
            </goals>
            <configuration>
                <groupId>myJar1.0</groupId>
                <artifactId>myJar1.0</artifactId>
                <version>1.0</version>
                <packaging>jar</packaging>
                <file>myJar1.0.jar</file>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 530
Melad Basilius Avatar asked Dec 19 '22 10:12

Melad Basilius


1 Answers

Actually its not so complicated.

There are 2 cases that you need to issue Maven’s command to include a jar into the Maven local repository manually.

  • The jar you want to use doesn’t exist in the Maven center repository.
  • You created a custom jar, and need to use for another Maven project.

Steps:

1. mvn install:

put your jar somewhere, lets assume its under c:\:

 mvn install:install-file -Dfile=c:\myJar{version}.jar 
 -DgroupId=YOUR_GROUP -DartifactId=myJar -Dversion={version} -Dpackaging=jar

Now, the "myJar" jar is copied to your Maven local repository.

2. pom.xml:

After installed, just declares the myJar coordinate in pom.xml.

<dependency>
     <groupId>YOUR_GROUP</groupId>
     <artifactId>myJar</artifactId>
     <version>{version}</version>
</dependency>

3. Done

Build it, now the "myJar" jar is able to retrieve from your Maven local repository.


NOTE: this example was based on the another example which I encourage you to read for further information.

like image 52
Gal Dreiman Avatar answered Dec 29 '22 01:12

Gal Dreiman