How to add jar file in your Maven local repository using command line


To add a local jar file in your Maven local repository, create a local maven repository. For example, I have master project on ${master_project} and subproject on ${master_project}/${subproject1}.

I am creating mvn repository in : ${master_project}/local-maven-repo.In pom file in subproject located ${master_project}/${subproject1}/pom.xml repository needs to be specified which would take file path as an url parameter.

<repositories> <repository> <id>local-maven-repo</id> <url>file:///${project.parent.basedir}/local-maven-repo</url> </repository> </repositories>
To specify dependency for any other repository use the code in the below snippet. This makes your repository independent. For instance, once desired jar is available in maven central you just need to delete it from your local repository and it will be pulled from default repository.
<dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.servicebinder</artifactId> <version>0.9.0-SNAPSHOT</version> </dependency>
Then, add jar file to local repository using -DlocalRepositoryPath switch like in this code:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \ -Dfile=/some/path/on/my/local/filesystem/felix/servicebinder/target/org.apache.felix.servicebinder-0.9.0-SNAPSHOT.jar \ -DgroupId=org.apache.felix -DartifactId=org.apache.felix.servicebinder \ -Dversion=0.9.0-SNAPSHOT -Dpackaging=jar \ -DlocalRepositoryPath=${master_project}/local-maven-repo
Once jar file is installed, such mvn repository is committed to code repository and the whole setup is system independent.

Solution Worked 0 UpvotesUpvote


Solution Didn't Worked 0 DownvotesDownvote