Friday, July 13, 2012

Install local jars with maven

I don't know why it took me a long time to write about this.

There are a lot of Java jars that isn't on the maven repository but you still need or like to manage these jars via Maven. To install a jar into your local Maven repo:

 
mvn install:install-file -Dfile={file} -DgroupId={groupname} -DartifactId={artifactname} -Dversion={versionnumber} -Dpackaging=jar
 
For example, you want to add Microsoft MSSQL jdbc driver into your local Maven repo then the procedure would be:
  1. Download and extract the file.
  2. Open the command line and type in:
  3.  
    mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=mssqljdbc4 -Dversion=4.0 -Dpackaging=jar
     
    
You can then add it to your project with:
<dependency>  
<groupId>com.microsoft.sqlserver</groupId>  
<artifactId>mssqljdbc4</artifactId>  
<version>4.0</version>  
</dependency>