Alpha
Alpha

Reputation: 14036

Download jars from local disk space to .m2 repository using pom.xml

I'm working on moving simple java project(which is pretty old) to Maven based and in current project all required jars are kept in lib folder.

For each jar in lib folder, I'm searching for respective dependency in maven central repository - https://mvnrepository.com/ and adding that dependency in pom.xml

But there are certain jars which I am not able to find at central maven repository and there is no source on team for me to help to identify the location(in case of third party).

One way is I can upload those jars to some repository like Nexus and in pom.xml, I can mention the url of it under repository tag so after hitting mvn install those will be added to .m2

But at the moment, I also don't have any location where I can upload those jars. So I'll put them in one folder on my machine.

Just wanted to know if there is any way in maven(mentioning something in pom.xml) which will point to that folder(in case jar is not available in central maven repo) and download it to .m2

Upvotes: 1

Views: 4557

Answers (3)

Ranjith Bokkala
Ranjith Bokkala

Reputation: 379

If you want to store jar's into local repository use below command.

You can do by using eclipse and command line.

eclips : install:install-file -Dfile=LOCAL JAR PATH -DgroupId=com.xxx.xx -DartifactId=JAR NAME -Dpackaging=jar -Dversion=JAR-VERSION

command line : mvn install:install-file -Dfile=LOCAL JAR PATH -DgroupId=com.xxx.xx -DartifactId=JAR NAME -Dpackaging=jar -Dversion=JAR-VERSION

You can use it with the help of below-given dependency in pom.

         <dependency>
              <groupId>com.xxx.xx</groupId>
               <artifactId>JAR NAME</artifactId>
              <version>JAR-VERSION</version>
         </dependency>

Upvotes: 0

Matteo
Matteo

Reputation: 487

If you dont' have a maven repository to use, the first option I can think is installing 3rd party JARs with maven in your locale maven repo, you can do it two ways :

1) Command line : mvn install:install-file -Dfile= -DgroupId= -DartifactId= -Dversion= -Dpackaging= Here is the official mavinstalling 3rd party JARs

2) Using maven-install-plugin (For instance for a project I was distribuiting a project with jars inside to distribuite to all developers in the team as environment setup) :

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <groupId>some_group_id</groupId>
                <artifactId>some_artifact_id</artifactId>
                <version>some_version</version>
                <packaging>jar</packaging>
                <file>path to jar</file>
                <generatePom>true</generatePom>
            </configuration>
            <executions>
                <execution>
                    <id>install-jar-lib</id>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>

Edit: I have read the other answer which suggest using systemPath in dependancy.

Of course this is an options, but in the original topic was asked : "Just wanted to know if there is any way in maven(mentioning something in pom.xml) which will point to that folder(in case jar is not available in central maven repo) and download it to .m2"

Using systemPath would not do that ans would require that the jar is always available in all system in the same path. I used it a few time and it works well mainly on projects you don't need to share with other team members. I would not recommend that, imagine a scenario where team is using different OS (windows and linux), you should configure different profile activating them by OS or have some path defined in the same way on all systems). Additional with system scope, the beahviour is the same as "provided" when including the dependancy in a WAR or EARfor instance. In my experience installing in local repo the jars with a configuration step has less drawbacks.

Hope I could be of help.

See you

Upvotes: 5

Nagaraju Chitimilla
Nagaraju Chitimilla

Reputation: 610

Use below dependency to include the jar available in the local machine to maven.

<dependency>    
  <groupId>groupid</groupId>    
  <artifactId>artifactid</artifactId>   
  <version>1.0</version>    
  <scope>system</scope> 
  <systemPath>${basedir}\lib\JAR_NAME.jar</systemPath>  
</dependency>

Upvotes: 3

Related Questions