Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • External Dependencies in Maven Project

    • 0
    • 2
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.40k
    Comment on it

    Dear programmers,

    There may many chances when you try to add external dependencies in your Maven project. Let's learn this how we can add our own jars or external jars in a project with an example.

    There are many Maven plugins available, And one of them is install-file, witch could be use to fix the problem. It creates and adds external jar to a local repository and make available to use in Maven project.

    Syntax :

    mvn install:install-file -Dfile=<complete-path-to-the-jar> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=jar
    

    For example -

    mvn install:install-file -Dfile=/home/dinesh/workspace/samples/Prototype/lib/siperian-common.jar -DgroupId=custom -DartifactId=siperian-common -Dversion=0.1 -Dpackaging=jar
    

    If everything goes fine, logs like the following appears on console.

    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Prototype 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-install-plugin:2.3:install-file (default-cli) @ Prototype ---
    [INFO] Installing /home/dinesh/workspace/samples/Prototype/lib/siperian-common.jar to /home/dinesh/.m2/repository/custom/siperian-common/0.1/siperian-common-0.1.jar
    [INFO] Installing /tmp/mvninstall1764840435348692554.pom to /home/dinesh/.m2/repository/custom/siperian-common/0.1/siperian-common-0.1.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.613s
    [INFO] Finished at: Tue Jun 16 12:38:33 IST 2015
    [INFO] Final Memory: 6M/148M
    [INFO] ------------------------------------------------------------------------
    

    Now the jar is available in local repository and can be defined as a dependency in your Maven project like -

    ..
    <dependency>
            <groupId>custom</groupId>
            <artifactId>siperian-common</artifactId>
            <version>0.1</version>
    </dependency>
    ..
    

    Thanks, Happy coding.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: