Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Tuesday 4 March 2014

Using MD5 checksum utility on Mac OS X

If you might be aware, every Linux distribution comes with the MD5 checksum utility - md5sum. Similarly UNIX flavors like Mac OS X, come pre-bundled with utility called md5

The OS X md5 utility can be found at /sbin/md5

I'll quickly show some steps on how to use it :

  • Open Terminal
  • Create a blank empty file anywhere on the system (I mean just anywhere) using touch


Eg : touch test.xml
  • Now type the following to generate the md5 checksum of this file 
Eg : md5 test.xml > test.xml.md5

That's it. Now open the test.xml.md5 using TextEdit or Text Wrangler and you'll see the file's equivalent md5 checksum. 

If you want to change the format of the output similar to Linux's md5sum use the -r switch 

Eg : md5 -r test.xml > test.xml.md5

Note that MD5 checksums are used to verify the integrity of a file. Even a single new character added to the file will change the equivalent md5 output. Check for yourself. Modify the test.xml by adding some content to it. Now run the md5 utility again as shown above. The md5 equivalent of the file will now be different. The checksums are important to verify that the files / resources are intact throughout and ensure that they are not corrupt or tampered.

You can use this method to verify the integrity of zip or tar files that you download from the internet.

A free utility Checksum Validator is also available. At the heart of it's gui, it uses this md5 command.

This information can come particularly handy while using Maven as well. Suppose for some odd reason, you have to manually create md5 checksums of the dependency jar's - then this method tells you how to do it.

Tuesday 25 February 2014

Repositories in Maven - A Refresher

Before covering a topic on Nexus repository manager, let's first understand the various types of repositories in Maven. In Apache Maven, there are 3 basic types of repositories :

  • Local
  • Central
  • Remote
Let me quickly cover a few basics about each one of them :

The Local Repository is the local folder on your machine that you mention in the project's settings.xml with <localRepository> tags. This is where all the artifacts - plugin jars, dependencies and other configuration files that Maven downloads, would be stored. 

The Central Repository is http://repo.maven.apache.org/maven2 which redirects you to http://search.maven.org/#browse. If the dependencies are not found in the local repository, Maven attempts to download them from this central repository. This is Maven's official central repository, where you search for various artifacts. This is analogous and similar to Perl's CPAN for searching modules.

Note that at the time of build, the download of dependency is triggered only if the required dependency is mentioned in pom.xml.

On certain occasions, it may happen that the required dependency does not exist on either local or central repository. It may exist on some other Remote Repository. For instance : Jboss or Java.net repository. In that case we have to mention the remote repository url in the pom.xml so that at the time of build, Maven will scan pom.xml and download the dependency jars from the mentioned remote url.

Remember, the thumb rule for Maven's dependency management is as follows : 
  1. First it will search local repository for the dependency.
  2. If dependency is not found in local repository, it will download it from central repository. 
  3. If dependency does not exist on either local or central repository, it will download it from the remote repository url mentioned.
Guys, more Maven posts are in the pipeline. Lots of useful information is coming up. Be positive, stay healthy and enjoy your life :)

Monday 24 February 2014

Installing Apache Maven on Mac OS X

Well, all new Mac machines loaded with Lion and above, come pre-installed with Maven. In order to find out which version is installed on your machine by default, just type the following in terminal :

mvn -version

Mine came pre-loaded with v3.0.3 and the default Maven Home was set at /usr/share/maven

However you if want to upgrade the version or configure the Maven Home to a different location, perform the following steps :

  • After downloading, unzip it and copy the entire folder to some other directory. Let's say for instance - /usr/lib/apache-maven-3.2.1
  • We now need to a couple of environment variables to our bash profile. In terminal, type vi ~/.bash_profile and insert the following variables to it ( i for insert ).
  • Now lets add the environment variable M2_HOME so type export M2_HOME=/usr/lib/apache-maven-3.2.1
  • Also define the M2 environment variable so type export M2=$M2_HOME/bin
  • Next type export PATH=$M2:$PATH and save .bash_profile and quit ( :wq )
  • Finally type source ~/.bash_profile. Note that when you close and open a new shell, the same settings will be intact.
Confirm the new settings by typing mvn -version to see the updated Maven version and home.
Congratulations, you just customised Maven on your machine. 

Just as am writing this post, am thinking about some stuff about Nexus repository manager which will enable you to manage your Maven repositories. Never mind, I'll cover Nexus in another upcoming post. Stay tuned :)
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker