Sunday, September 25, 2016

Adding External Jar In Maven Project

We know that maven is a build management tool. So when ever we need to add any jar for our project we can mention dependencies in POM(Project Object Model) file(xml file) then it automatically pull the jar from remote repository(default Apache Maven repository) and store it in default location(C:\Documents and Settings\User\.m2) if it is not available under this location.

But what happen if this jar is not available on remote server, but we need this jar to run our project. As well as we have no permission to upload this jar in any maven repository due to some security or restriction.

So maven provide us different way here we discuss two ways:
  1. Add jar in System Property.
  2. Use jar as project specific local Repository.
1. Add jar in System Property

For this we need to mention the path of this jar under <systemPath> tag and mention system under <scope> tag.

e.g :

<dependency>
    <groupId>group id name</groupId>
    <artifactId>artifact name</artifactId>
    <version>version number</version>
    <scope>system</scope>
    <systemPath>jar location</systemPath>
</dependency>


2. Use jar as project specific local Repository

For this we need to create a specific folder structure in our project as given below



and mention the repository path under <url> tag like file://${project.basedir}/lib
e.g :
        <dependency>
            <groupId>seleniumserver</groupId>
            <artifactId>seleniumserver-sdk</artifactId>
            <version>2.53.0</version>
        </dependency>
        <dependency>
            <groupId>seleniumclient</groupId>
            <artifactId>seleniumclient-sdk</artifactId>
            <version>2.53.0</version>
        </dependency>



    <repositories>
    <repository>
        <id>in-project</id>
        <name>In Project Repo</name>
        <url>file://${project.basedir}/lib</url>
    </repository>
    </repositories>