Saturday, 31 January 2009

A simple approach to setting up a maven repository

At last, after I dont know how long I decided to try maven. I knew it is there and it is good,but I guess the final push for me to use this came from that fact that I wanted to manage my jar files better between all my personal projects. I had the trouble of syncing my Linux and Windows systems to the same version of jars while working on Console4Jython, so I decided to wisen up as I tried to finally kick start the other two projects.

Setting up maven locally was simple, and I am happy that now I can just depend on the maven central repository to get all the jars downloaded between my two boxes. I couldn't wait to migrate Console4Jython to Maven - but then I realized that there are jars that I want and are not available on the repository. One way would have been to search for the repositories for these and add them, but thankfully, I decided to set up my own repository and learn. Here is how it is:

  • Get a HTTP server somewhere on the network - I am using my web hosting on the internet
  • Create a folder called "myrepo" in the HTTP root of the server.
  • Inside this "myrepo" , create a folder called "m2-repo"
  • Check that you can access this from all the machines where you will work from, this might be necessary of your repo is on the internet and you might have to configure a proxy. I had to set up the web proxy
Now, I am assuming you have installed the jar to your local repository, if not you can do it by typing a command like

mvn install:install-file -Dfile=jyaml-1.3.jar -DgroupId=yaml -DartifactId=jyaml -Dversion=1.3 -DlocalRepositoryPath=C:\Users\hari\.m2\repository -Dpackaging=jar


Here I am trying to install the JYaml library. For further details you can refer to the maven documentation.

Once you have done this, you can go to your local repository and you will find a folder ~/.m2/repository/yaml. To set up the remote repository you will need to copy this structure to the m2-repo folder that you created previously. But before that you need to geneate an md5 for each file in this directory structure. I used the md5 for Windows tool from here.

Using this create the md5 files for all the files in the directory except the files names *.sha*.

Once that is done, copy the top level folder, in this case yaml, to the m2-repo folder. If you access the url http://myserver:port/myrepo/m2-repo, you should see the following structure

Now add this repository URL to your POM - it should be able to update the jar files.

0 comments: