A few days ago someone asked me if my MoneyJar application was available online to view. Unfortunately I hadn’t made it that far. All my development so far had been using MAMP to run a web development server locally on my desktop computer, until now.
I knew that I wanted to learn to use Heroku – a cloud based application hosting service. But I wasn’t entirely sure how, nor was my project ready for it. But after having to disappoint some people about the application’s availability I decided it was time to take the plunge.
Switching To Maven
First of all I had to switch from the Ant build tool to Maven. Unlike Ant, I have not learned anything about Maven. Largely because Maven seemed like a bit of a mystery to learn – one StackOverflow user once commented:
To those who understand Maven, no explanation is necessary. To those who don’t, no explanation is possible.
But I decided to give myself a crash course anyway. Surprisingly it wasn’t too difficult to set up with a little help.
- 4 Simple Step to Migrate Legacy Project from Ant to Maven
- StackOverflow: How can I replace Ant with Maven
I just had to change my directory structure to match the Maven convention, and then add all my dependencies to the pom.xml file and then build it. Unlike Ant, there was surprisingly very little configuration needed. I guess this is what they call “convention over configuration” – and I love it.
Fortunately the build process for my project was not complex and the migration happened without much fuss. For a more complex project I can imagine it wouldn’t be long before you run into problems. But otherwise, if your project only needs to compile classes, run tests, and package the classes into a jar/war distribution then the migration isn’t too difficult.
Switching To PostgreSQL
Another problem I ran into while migrating my project to Heroku was my choice of database management system (DBMS). Because I was using MAMP (Mac, Apache, MySQL and PHP) to host my project locally, it meant that I had been developing for MySQL as my DBMS. This was unfortunate because Heroku appears to only provide support for PostgreSQL applications.
So I began my painful migration from MySQL to PostgreSQL – or at least I thought it would be painful. Thanks to good programming practices, using a DAO and Hibernate to decouple my application from the DBMS the switch was just a change of dependencies and updating the Hibernate configuration files to access a local PostgreSQL database.
The migration initially broke my application’s database queries. However, I did manage to fix most of it with a little SQL tweaking in the relevant DAO class. There is still one that doesn’t appear to be working: Changing the Category ID of multiple transactions – it doesn’t appear to like how I’ve organized my sub-query. This is a bug I need to fix soon.
Uploading To Heroku
Finally my web-application was ready to deploy to Heroku. Signing up was free, and you get a nice introduction to Heroku and how to get started. The first 700 dyno hours are free, and your app is allocated a small hobby PostgreSQL database.
After that, it was just a matter of installing the Heroku command line tool ‘Heroku Toolbelt‘. Creating an app on Heroku. Committing my application files to my local git repository, and then pushing the whole repository to Heroku where the project is then automatically built and packaged (using Maven), and then deployed to a random Heroku URL (which you can rename). After that, bash in ‘heroku open’ in your terminal and a browser opens leading you to your online application.
Admittedly the first few times I did this the application immediately crashed, due to a few missing dependencies and a few quirks configuring Hibernate to work with Heroku.
It turned out I had been using an old configuration method for configuring Hibernate, and I had to figure out the newer configuration – integrating Hibernate with Spring MVC using Spring beans. This took a few hours to figure out but in the end was a major improvement to my project as a whole. It just goes to show, it you want to make your project better, make changes and see what problems you run into.
First of all, I was very glad that I took the time to learn clean coding practices and had given the application descriptive method names. This made navigating the code much easier. I was also glad that the code is modular and fairly well organized considering that I am still a novice programmer. All of this made me realize that these practices were not done in vain but play an important role in making your code base comprehensible.
Still, the MoneyJar project is still a work in progress and in its current state, it is just a walking skeleton. There is still much to do, including figuring out managing users, encrypting data, and adding a plethora of reports and analysis. So until then, the project is still in an experimental phase. Which it is of course, because it’s just my test rig for trying out different technologies and frameworks.
At the moment there are a couple of front end frameworks I would like to explore: namely AngularJS and Boostrap. I’m sure I’ll be integrating these technologies into a new front-end soon.