Thursday, March 31, 2011

Manage Local Maven Dependency

Recently, I came across an issue while running build for Maven pom.xml. I am using Hibernate Shards project in my product, and updated pom.xml with following:


            <dependency>
                  <groupId>hibernate</groupId>
                  <artifactId>shards</artifactId>
                  <version>3.0.0B2</version>
            </dependency>


Though when I ran the pom.xml with the above xml snippet, it was not able to find the hibernate shards jar file in the Maven repository and could not download it.
I searched the Maven repository for hibernate shards file, but could not find it. Maven repository is available here - http://mvnrepository.com/

Solution
When a pom.xml file is run using “mvn install” command, as part of the build, Maven fetches the jar files from the Maven repository on the internet.  These jar files are stored under a folder called “.m2” under the users folder.
In this case, since the Hibernate Shards file is not available in the Maven repository, we have to manually run Maven command to install this jar file under the “.m2” folder. So here’s the command,

mvn install:install-file -Dfile=c:\Downloads\hibernate-shards-3.0.0.beta2.jar -DgroupId=hibernate            -DartifactId=shards -Dversion=3.0.0B2 -Dpackaging=jar -DgeneratePom=true


Now when the pom.xml build file is run with “mvn install” command, the build runs successfully, since the local “.m2” folder repository is checked for hibernate shards jar file.

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete