Wednesday, January 15, 2014

How to setup a Maven repository?

Setting up a Maven repository was a major requirement in one of my projects. It is a simple task but since it was first time I tried it out, I faced few issues in that, So that I have decided to add a small post to my blog this time. 

First of all, you have to make sure that the latest JDK is installed in your machine and the paths for bin folder is set accordingly. 

Then you have to download and install maven in your machine. Follow the below link and get the zip file downloaded.


select the below highlighted link to get the zip file downloaded



















extract the zip file to the below location 

C:\Program Files\Apache Software Foundation 

Note that I initially didn't have such folder in my machine, so that I created a folder named Apache Software Foundation in the above location. 

Though I mentioned above as 'download maven and install', it's not going to be an installation following a wizard but it's the matter of setting some environment variables for the bin folder.

Set the M2_HOME environment variable


Type env under startup search box ( in windows) and select Edit the system environment variables option from the search results box. under User variables for <username> panel, click New. Then add the following

Variable Name: M2_HOME
Variable Value: C:\Program Files\Apache Software Foundation\apache-maven-3.1.1

Then close all three opened windows by clicking OK buttons in each of them.

Append the maven bin folder path to the path variable


Type env under startup search box ( in windows) and select Edit the system environment variables option from the search results box. Next click Environment Variables under Advanced tab and then focus on path under System variables. Select it and then click Edit. Then place the cursor under variable value text box and go towards its end then add a semicolon and paste the path to the maven bin folder (e.g :- C:\Program Files\Apache Software Foundation\apache-maven-3.1.1\bin). Then close all three opened windows by clicking OK buttons in each of them.

now you are almost done with the installation. To make sure that you have set the paths correctly, type the below command in a command prompt (in windows)

mvn -v





















Note: the correct version of maven that you installed should be shown above. 

now depending on the maven project and the required dependencies the command that you use to create the m2 repository differs. 

I use a connector project that requires java libraries as dependencies from maven repository. so, that it has a connector project folder, I have to go to the location where there is a pom file and type the below command to build the project, if in case the m2 repository is not yet created, this command will create it.

first naaviagte to the drive where your project is by typing the below command (assume that the project is in drive E)

E:

then navigate to the project folder by typing the below (note that the om file should bemlocated in the below shown location as well)

cd E:\Connectors\org.cmp.carbon.connector

now type the below command

mvn clean install

now go to the below shown location and check whether the .m2 folder is created for you.




















Additional tip:

If you want to get this maven project to eclipse as an eclipse project then type the below command inside the project folder (where the pom file is located)

mvneclipse:eclipse -Dwtpversion=2.0

hope it was useful to you. If so, please leave a comment