Category Archives: Java

Development Environment II

I’ve been rethinking using Eclipse as my Java & HTML5/JavaScript IDE of choice since discovering that NetBeans 7.3 supports both, and with integrated Chrome JavaScript debugging and Twitter Bootstrap, BackBone.js and Jersey RESTful WebServices support it seems too good to be true. But after getting a couple of building a couple of simple apps with NetBeans it could be time to wave goodbye to Eclipse plugin hell and say hello to NetBeans simplicity.

One thing I couldn’t figure out was why the CustomerDBSpring sample app and the CustomerRestfulService¬† app were producing different JSON. It turns out it was all down to how Jersey was configured to convert Java to JSON. This guy describes the problem well and the first solution that I tried, but clearly that wasn’t a great long term option. The longer term solution was to use Jersey’s POJO support, which basically amounts to sticking this in your web.xml.


BTW I don’t usually blog on a Saturday night, not that I’m saying there is anything wrong with that, but its just that my wife is watching the final of Strictly Come Dancing ūüė¶


Development Environment

The development environment is based on Mac OS X, Eclipse 4.2 (Juno) for Java development and Google Chrome with the JSONView plugin for JavaScript debugging.

One of the challenges was to replicate the technical architecture of the production environment in the development environment. Installing Apache HTTP Server, Apache Tomcat and MySQL was a skoosh but mod_jk on OS X was a different issue. In fact I had problems with the subversion plugin for Eclipse 4.2 and upgrading from Eclipse 3.6 to 4.2.

No easy download and install for mod_jk on Mac OS X, oh no you have to get the source code and build it your self. After downloading the mod_jk source …

cd tomcat-connectors-1.2.37-src
./configure --with-apxs=/usr/sbin/apxs
cd native/
./configure --with-apxs=/usr/sbin/apxs
CFLAGS='-arch i386 -arch x86_64' APXSLDFLAGS=' -arch i386 -arch x86_64' ./configure --with-apxs=/usr/sbin/apxs
sudo make install

And bish, bash, bosh I had a /usr/libexec/apache2/

Eclipse 3.6 to 4.2 upgrade
Upgrading from Eclipse 3.6 to 4.2 didn’t work, but I put that down to the Flex plug-in. I gave up on that upgrade and installed a new 4.2 version and backed out the upgrade on 3.6 with the wonders of Time Machine. I need the 3.6 version to support the Flex apps I’ve built with Eclipse 3.6. I have an elephants graveyard eclipse versions on my machine.

Unfortunately the 4.2 Juno release initially ran like a dog. It would take several seconds to just open a file, I’m not the only one to experience this¬†problem. Increasing the memory allocation in the eclipse.ini file¬†soon¬†sorted this problem though…


Subversion plugin
Using the subversion plugin from ¬†Eclipse 4.2 on Mac OS X also needed a bit of work, this time having to install subversion and a load of other Darwin port stuff. The magic that worked for me was…

sudo port install subversion-javahlbindings +no_bdb +universal
sudo port -f activate subversion-javahlbindings

Technical Architecture

I’ve decided to build the playermanager app with a classic 3-tier architecture;

  • HTML5 presentation tier
  • Java RESTful web services middle tier
  • MySQL database data tier

HTML5 presentation tier
Choosing HTML5 and JavaScript for the front end was a difficult decision. After putting a fair bit of effort into Flex in the last five years it felt bad ditching ActionScript in favour of ¬†its ugly sisters HTML and JavaScript but with the likes of Twitter Bootstrap and Backbone.js things have changed a lot since I last fiddled with them. There seems little no point in dusting off my ancient copies of HTML: The Definitive Guide ¬†and¬†JavaScript: The Definitive Guide, or even giving them to the ¬†Scouts Fall Fair, I’ll just need to splash out on new ones.

This tier will be served alongside other static web content from the website on an Apache HTTP Server, passing any Java RESTful API calls to the Java tier below via mod_jk.

Java RESTful web services middle tier
A RESTful web services tier seems like a good a choice from a Service Oriented Architecture view, developing services so that different clients, e.g. mobile apps, browsers, FIFA, can make use of playermanager services via a RESTful API.

Choosing Java for the implementation of the RESTful API was a fairly easy decision. In my experience RESTful Java web services written in Jersey producing and consuming¬†JSON are a very lightweight and productive option. Using Spring¬†in the Java tier seemed like a good choice based on industry best practice and extensive Jobserve research; Spring Security to secure the RESTful API, Spring’s data access framework with Hibernate to simplify the reading and writing of data in addition to Spring’s dependency injection are all tried and trusted methods.

The Apache HTTP Server of the tier above passes on any Java RESTful web services API calls to an Apache Tomcat Java Server that services any URL beginning /api.

MySQL database data tier
MySQL was an obvious as its simple and open source with good developer and admin tools.

Currently all of the tiers above run on one CentOS machine, hosted by enciva for £10 per month, but there is scope for scaling this architecture when playermanager goes global. And will scale further with the addition of caching where appropriate, e.g. mod_cache and Ehcache.

So that’s the architecture in a nutshell. Next up is the development environment.