Saturday, July 17, 2010

Adding a custom jar to maven-repo effectively

Hi

Maven gives a wonderful way to add custom jars to maven-repo and make use of the jar in the project. Here is how it is :

If You have a jar not available in maven repository but it is needed for your project
thereby when maven build your project, you want maven to pick from the local repository instead of downloading it from the web or maven URL (http://repo1.maven.org/maven2/)

For Example :

I have a hibernate-jpa-custom jar which i want to use the jar available with me while doing maven build

Steps to follow that:

1) First install the jar into local maven-repository using

mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate-jpa-custom -Dversion=2.0 -Dpackaging=jar -Dfile= -DgeneratePom=true


Going by the command :

groupId - denotes the group of the artifact
artifactId - name of the artifact
version - version of the artifact which you want to use in your project
file - the jar library
generatePom - to generate pom for the jar file automatically
this option is very important in order to avoid errors like

[INFO] Copying 0 resource
Downloading: http://repo1.maven.org/maven2/org/hibernate/hibernate-jpa/2.0/hibernate-jpa-2.0.pom
[INFO] Unable to find resource 'org.hibernate:hibernate-jpa:pom:2.0' in repository central (http://repo1.maven.org/maven2)

Since there is no pom available to look in the local repository, maven tool assumes that there is no jar in local repository and has to contact maven repo URL to download the jar thereby showing the error message "unable to download"

2) make a entry in the pom.xml of your project for the jar which you just added to local maven repo
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpa-custom</artifactId>
<version>2.0</version>
</dependency>

3) use mvn install to do a install of the project with newly added jars

Now your project will make use of the custom jar

let me know in case of any queries

Thank You
Ram Prasad

No comments:

Post a Comment