Tuesday, October 23, 2012

How to include custom jar into your Maven repository?

Still you will find jars which are not there in Maven repository. Classic example is suppose you create a common utility jar and you want to use it across projects or it could be a third party jar which has private licence and so cannot be there in Maven central repository. In above cases, you can actually put the required jar easily in the Maven local repository. For demonstration purpose, we are using Kaptcha.
Here is the command:
mvn install:install-file 
-Dfile=c:\kaptcha-2.3.2.jar 
-DgroupId=com.google 
-DartifactId=kaptcha 
-Dversion=2.3.2 
-Dpackaging=jar

Remember to remove the newlines from above command incase you are copying and pasting.
Below is the result from command line after executing the command:
C:\>mvn install:install-file -Dfile="c:\kaptcha-2.3.2.jar" -DgroupId=com.google
-DartifactId=kaptcha -Dversion=2.3.2 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-po
m ---
[INFO] Installing c:\kaptcha-2.3.2.jar to C:\Users\dharmvir.singh\.m2\repository
\com\google\kaptcha\2.3.2\kaptcha-2.3.2.jar
[INFO] Installing C:\Users\DHARMV~1.SIN\AppData\Local\Temp\mvninstall71581647865
23828175.pom to C:\Users\dharmvir.singh\.m2\repository\com\google\kaptcha\2.3.2\
kaptcha-2.3.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.587s
[INFO] Finished at: Tue Oct 23 15:23:57 IST 2012
[INFO] Final Memory: 3M/15M
[INFO] ------------------------------------------------------------------------
Job is done. You can now specify the dependency of this jar as shown:

      com.google
      kaptcha
      2.3.2

Monday, October 15, 2012

Configuring Maven inside proxy network

Maven version I used is 3.0.4 and environment is windows 7 enterprise edition.

Well, it is pretty simple,

collect your proxy server and port configuration and if username and password  are there then them too and save them in your settings.xml.
Settings.xml can be found either in <userhome>/.m2/settings.xml (Apache documentation tells about this path but I couldn't find it in this location, link to proxy config doc.. proxy config mini guide) or (I found them in this path <maven unzipped directory>/config/settings.xml, in my case path was D:/apache-maven-3.0.4/config/settings.xml)
Now, you have to uncomment this section from settings.xml and save the correct info here as shown:
 
    
    
      optional
      true
      http
      proxyuser
      proxypass
      Your Proxy server IP Here
      Your proxy server port numbere here
      local.net|some.host.com
    
    
  

Related Articles

Eclipse proxy setting