This morning I spent my time commuting to work reading about a Test-Driven Development Stack for Java. Tools mentioned were Maven, Jetty, Mockito, and JAX-RS. I wanted to learn some more about Mockito so I spent some time reading on their website where I found out about this build automation system called Gradle that can be used instead of Maven. Interesting I thought, let's try it out.
So first things first. The Ubuntu repositories only contained a really old version of Gradle so I downloaded the binary distribution from the website. Installation consisted of the tricky task to decide where to extract the archive and set up my PATH to include the bin directory for Gradle.
Then I thought that I wanted a plugin for Eclipse so I can create Gradle projects and have some parts automatically generated. After searching the web for a short while I found Buildship that is a collection of Eclipse plug-ins that provide support for building software using Gradle.
The easiest way to install it in Eclipse is to use the Eclipse-Marketplace. A nice tutorial written by Lars Vogel can be found here.
Now that I had a Gradle project in Eclipse it was finally time to pick up on the JSON in Java mini-project I started on yesterday. Adding Google's JSON Java library to the Gradle project was a piece of cake. Just add the line compile 'com.google.code.gson:gson:2.6.2' in the dependencies section of the build.gradle file and you are ready to go.
Using the GsonBuilder makes it really pleasent to create Java objects from JSON strings. I created a simple User class with the private variables 'name' and 'age' and created new users by calling
User user = new GsonBuilder().create().gson.fromJson(jsonString, User.class);
You Java developers are really spoiled with nice tools and cool libraries ;).
So first things first. The Ubuntu repositories only contained a really old version of Gradle so I downloaded the binary distribution from the website. Installation consisted of the tricky task to decide where to extract the archive and set up my PATH to include the bin directory for Gradle.
Then I thought that I wanted a plugin for Eclipse so I can create Gradle projects and have some parts automatically generated. After searching the web for a short while I found Buildship that is a collection of Eclipse plug-ins that provide support for building software using Gradle.
The easiest way to install it in Eclipse is to use the Eclipse-Marketplace. A nice tutorial written by Lars Vogel can be found here.
Now that I had a Gradle project in Eclipse it was finally time to pick up on the JSON in Java mini-project I started on yesterday. Adding Google's JSON Java library to the Gradle project was a piece of cake. Just add the line compile 'com.google.code.gson:gson:2.6.2' in the dependencies section of the build.gradle file and you are ready to go.
Using the GsonBuilder makes it really pleasent to create Java objects from JSON strings. I created a simple User class with the private variables 'name' and 'age' and created new users by calling
User user = new GsonBuilder().create().gson.fromJson(jsonString, User.class);
You Java developers are really spoiled with nice tools and cool libraries ;).
Kommentarer
Skicka en kommentar