Using Third-party jars with Maven

Refer: 20120512 Using Third-party jars with Maven

To use third party jars in a maven project, the steps are as follows:

1) Upload the jar into a repository (either your local repository if it's just for you, or into the shared Nexus repository if you want other people to access the jar as well)
2) Add a section in your pom.xml to tell maven that your application depends on this jar.

Here are the commands to implement those steps:

To upload a jar in your local repository (your local repository is on your vm in ~/.m2/repository):

mvn install:install-file
-Dfile= -DgroupId=com.hal.thirdparty
-DartifactId=
-Dversion=
-Dpackaging= -DgeneratePom=true

Where: the path to the file to load
the group that the file should be registered under
the artifact name for the file
the version of the file
the packaging of the file e.g. jar

To upload a jar into the shared Nexus Repository:

Option A: Command line

mvn deploy:deploy-file -Durl=file://C:m2-repo
-DrepositoryId=some.id
-Dfile=your-artifact-1.0.jar
[-DpomFile=your-pom.xml]
[-DgroupId=org.some.group]
[-DartifactId=your-artifact]
[-Dversion=1.0]
[-Dpackaging=jar]
[-Dclassifier=test]
[-DgeneratePom=true]
[-DgeneratePom.description="My Project Description"]
[-DrepositoryLayout=legacy]
[-DuniqueVersion=false]

See here for the detail of the options: http://maven.apache.org/plugins/maven-deploy-plugin/usage.html

Option B: Using the web interface from Nexus at http://halsvn01:8081/nexus/index.html#view-repositories;thirdparty~uploadPanel

See the attached screenshot.

In both options, you will need Nexus admin credentials to upload artifacts (jars in maven terms) into the shared repository.

2) In your pom.xml, inside the section, add:
com.hal.thirdparty
your-artifact
your-artifact-version

-------------------------------------
Guillaume Radde
Senior Consultant, Red Hat Consulting
guillaume.radde@redhat.com
http://www.redhat.com
-------------------------------------

Leave a Reply