Preparing your environment for modern open source Java libraries and frameworks using Git and Maven, throwing in Tomcat as a bonus

In my investigations into jWebWSockets, Kaazing, Atmosphere, CometD 2 and other frameworks I came to understand that in order to get these frameworks installed, integrate them into my custom applications or run the samples to go with these products, it would be convenient if not essential to have an environment with Maven and Git operational – and having Tomcat ready to run helps too.

So I decided to set up these tools – and write a short article with some hints for future reference for me and anyone who might be interested. First of all, let me tell you that it took far shorter and far less trouble than I anticipated. It really was easy to have my environment prepared for big and beautiful things. In subsequent posts I will explain how to load and run the Atmosphere demos as well as the CometD 2 samples – leveraging the Maven and Git (and Tomcat) environment discussed in this article.

Note: my environment is Windows 7 (64 bit) and I am using JDK 6.0 (although most steps and resources are the same for Linux environments and MacOS as well).

Setting up local Maven support

First I downloaded the current latest distribution of Maven 3 from http://maven.apache.org/download.html. In my case this was apache-maven-3.0.3-bin.zip. I extracted the archive to C:\java\apache-maven-3.0.3.

Following the instructions in http://maven.apache.org/guides/mini/guide-configuring-maven.html I hardly did anything, as the defaults by and large are fine. An important default is the location of the local Maven repository – ${user.home}/.m2/repository.

Image

In the file ${user.home}/.m2/settings.xml, your specific Maven user configuration can be specified – including an alternative location for the default repository.

From the installation instructions at http://maven.apache.org/download.html:

Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the “Advanced” tab, and the “Environment Variables” button, then adding the M2_HOME variable in the user variables with the value C:\java\apache-maven-3.0.3.

In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.

Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.

In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.

Image

Open a new command prompt (Winkey + R then type cmd) and run mvn –version to verify that it is correctly installed.

Image

Get Git going

Many open source libraries seem to have their (re)sources located in Git repositories these days, typically at GitHub. In order to make use of these libraries and frameworks, get a run time environment going and run samples – it is adamant to have a local Git environment set up that allows us to clone Git repositories to the local environment.

Using http://www.vogella.de/articles/Git/article.html to get me started on what Git is and what I can expect from it – and how to get going with it – it was easy to configure my environment.

Go to http://code.google.com/p/msysgit/ to download Git for Windows (http://code.google.com/p/msysgit/downloads/list?can=3&q=official+Git).

This comes with a Windows installer – no complex configuration file wrestling this time.

Image

I ran the installer.

The installer added the Git\cmd directory to the Windows Path variable:

Image

In the Windows programs list, there is the following Git entry:

Image

Following Lars’ instructions in the Git tutorial, I configured Git locally – from the command line:

Image

These settings end up in the .gitconfig file. This file is located in the user home directory.

Image

I have create directory gitrepos – that is where I intend to create my own repositories and clone remote (3rd party) repositories.

As Lars’ describes, one can use GitHub (or BitBucket) as a remote Git repository – either private or available to the general public. GitHub can be found under the URL https://github.com/. GitHub is free for all public repositories, i.e. if you want to have private repositories which are only visible to people you select, you have to pay GitHub a monthly fee.

The instructions on GitHub for creating an account, creating a public repository and linking the local Git environment to the remote GitHub repository are very clear. A four step process starts at http://help.github.com/win-set-up-git/. Note that the instructions also explain the installation of Git on Windows.

Image

Install and configure (if necessary) Tomcat

Not immediately related to either Git or Maven, I will very briefly mention Tomcat as well. Many of the frameworks I have recently been studying have samples that supposedly run on a clean Tomcat environment (just build WAR file using Maven from the sources cloned from a Git repository and deploy to Tomcat).

The installation of Tomcat really could not be simpler: download zip file and extract to directory of choice. That is all.

For example:

Download Tomcat 6.0 from http://tomcat.apache.org/download-60.cgi (I needed Tomcat 6, rather than 7.0 for some experiment)

Image

Extract zip-file to c:\java

Image

If necessary configure Tomcat – especially the port on which it will be running – one can do so in apache-tomcat-6.0.35\conf\server.xml.

Using startup.bat in apache-tomcat-6.0.35\bin, the Tomcat server can be started. The Admin console for Tomcat can be accessed via http://server:8080/manager/html -or whatever the port number that was specified in server.xml.

Image