From code to deploy : a basic Java configuration

In this short guide I would like to give you a panoramic and a work-flow idea about Java programming and explain how to build a basic and standard environment to develop Java code, in particular if you want to share your project on Github.

First of all you need a good IDE. Personally I use IntelliJ IDEA, a powerful editor developed by Jetbrains downloadable here. IntelliJ has a lot of specific features and I think the most interesting for our purpose are the Versioning Control System and the ability to inject a Framework Support into the project.

Let’s see how can we add a Framework support. Usually I manage all the dependencies with Maven, a build automation tool developed by the Apache Software Foundation.

To add the framework support to your java project you can simply click on the root project folder (project structure window on the left of IntelliJ) and select “Add framework support”: select then Maven and apply. IntelliJ will create the entire structure and your code will be placed into /src/main/java

Code is not everything, in fact in a good Java software, the testing phase is very important to produce a good Java code (we hope). To apply a testing framework you can use Junit. To use Junit you can simply edit the pom.xml (Project Object Model) file and add the dependency inside the “<dependencies></dependencies>” tags.

At this point you can create a new java class at /src/main/test and build your test case. Here is a good guide.

We mentioned that IntelliJ can manage versioning systems like Git (obviously you must have it installed previously). So the first thing to do is to create a new repo on Github, initialize a new one locally and setup the remote link to Github. Here is a good guide. In IntelliJ you will be then able to open VCS (top menu) and commit/push the code on your Github remote repository.

Last but not the least is important to enable a Continuous Integration mechanism for your project. CI systems allow developers to build the project automatically in a remote environment created ad hoc for your project. I personally use Travis. Travis is accessible via Github oauth authentication. First you have to enable the repository to bind from the repos list. Then create a file into the root of your project called “.travis.yml “, put inside the default string “language: java” and push the repo.

If you have followed the previous steps everything will magically works and Github will speak with Travis to build the project in background. If the build is ok you will find in Travis Dashboard the information about the last build process.

At the end let’s inform other users and developers about the status of the build applying on your readme the Travis badge.

If you also want to deploy your software you will need a Continuous Delivery tool. I recommend Heroku. This platform is well documented and supports a very wide variety of programming languages.

So, the perfect environment to collaborate on a Java project is composed of these 5 components:

  • a powerful IDE – IntelliJ IDEA
  • a flexible versioning system – Git and Github
  • an easy testing framework – Junit
  • a magical Continuous Integration engine – Travis
  • a reliable Continuous Delivery system – Heroku

And now what will be your next project?

Cheers




This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.