Upgrading Maven on Mac OS X

Upgrading Maven on Mac OS X is generally nothing very special, but I’d like to summarize the steps I’ve done. Maybe it is helpful for users which are not so familiar with the Terminal application.

terminal_app

  1. First of all: start the Terminal application, located in the folder /Applications/Utilities/Terminal.app.
  2. Here you can find out which Maven version is currently running, by typing mvn -version. You will get some output starting with the Maven version number, such as: Apache Maven 2.0.9. The latest version of Maven is 2.2.1 by the time of writing this article, so you see there is the need to upgrade.
  3. Now you have to locate the mvn command in your file system. Type whereis mvn. The output will be the complete path of the executable: /usr/bin/mvn.
  4. This is most likely not the place where Maven is installed, but a symbolic link to the Maven executable of your system. To find out where this link refers to, type ln -sls -l /usr/bin/mvn (replace the path with your own mvn location). The output will look like this: lrwxr-xr-x 1 root wheel 37 2 Sep 22:39 /usr/bin/mvn -> /usr/local/apache-maven-2.0.9/bin/mvn
  5. Now change to the parent directory of the Maven installation. cd /usr/local
  6. Open Safari and download Maven from the Maven Homepage. Instead of downloading with Safari, you can also use a command line tool. Please use the mirror which is best for you: http://apache.linux-mirror.org/maven/binaries/apache-maven-2.2.1-bin.tar.gz
  7. Now extract the archive: tar -xzvf apache-maven-2.2.1-bin.tar.gz
  8. Optional: move the extracted archive to the right folder: sudo mv apache-maven-2.2.1 /usr/local
  9. Now link the Maven command to the new version: sudo ln -fs /usr/local/apache-maven-2.2.1/bin/mvn /usr/bin/mvn

That’s it. Now you can try if the latest version is actually installed. Type mvn -version again, and you will see:

Maven Version Output

If you are not able to execute the mvn command, it is possible that the execute flag is missing. Change this by typing chmod a+x /usr/local/apache-maven-2.2.1/bin/mvn

Self-made MVC web application in PHP

While PHP makes it easy to build small and simple dynamic websites, a strict architecture is difficult to obtain. It simply is too easy to mix logic, presentation and data access. In this post I will describe how a strict MVC architecture can be implemented easily without a third party framework. I focus especially on separating business logic from presentation. Please note, that the code examples show simplified code and details, such as error handling need to be added for production.

The core concept is the Request class:

abstract class Request {
    function execute($template) {
        $params = $this->prepare();
        include $template;
        $this->cleanUp();
    }

    function prepare() {
    }

    function cleanUp() {
    }
}

By overriding the method prepare(), business logic will be implemented and passed as parameter array params to the template. Optionally the cleanUp() method can be implemented to clean up after displaying the template – for example closing database connections etc. An example would look like this:

class MyRequest extends Request {
    function prepare() {
        $params = array();
        // do something and fill the $params array
        return $params;
    }
}

Finally the MyRequest class will be instantiated and called with the template path:

$req = new MyRequest();
$req->execute('template.php');

With this simple approach, logic and presentation can be easily separated; the template code is very clean and uses only the $params array. The business logic is encapsulated and does not contain any presentation specific references.

Run GAE Development Environment in Eclipse on the Mac

I mentioned already how to set up Eclipse to get code completion for the Google App Engine development environment. To run the application from inside Eclipse has some advantages, too: All errors are logged to the console and you can directly jump to the error location in the code.

The run configuration needs to use the following main module:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py

My Development Environment

As CloudMe will not just focus on Java development, but will also utilize GAE (Google App Engine), I had to modify my development environment to support Python. I decided to use Eclipse as I’m already familiar with it from the Java development (I tried NetBeans, which is also really good, and needs less memory, but being more familiar with Eclipse made the difference). For this project I did a clean install:

For GAE, some documentation is required (considering that I’m new to Python):