Search This Blog

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, September 8, 2011

Easy way of making a JSON array of JSONarrays of JSONObjects ans so on ... in JAVA


In my code, I had to make a JSONArray of JSONArrays which have JSONObjects which in turn can be JSONArrays.
When we try to do it in pure JSON way, it gets complicated, we have to create a lot of different variables and then add it to the main array.
There is a very simple way to do it. Just keep on creating a HashMap which can be a HashMap of HashMaps and so on.
Then when you create a JSONArray pass the HashMap to it as a variable to its constructor. It creates an entire JSONArray from it.

Thanks,
Shoeb

Wednesday, September 7, 2011

Adding a new repository in the maven pom.xml


At times, the repository used in the pom.xml may not have the latest version of jar you are looking for. In such case, you will need to add a repository which has the required version of the particulaar dependency. You can do it in the following way:

Add the following lines between the <repositories> </repositories> tags:
<repository>
<id>org.spring.maven.snapshot</id>
<name>Spring Maven Snapshot Repository</name>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>

Change the url and id according to your requirement. The id can be anything but should be a unique one.

Thanks,
Shoeb

Tuesday, August 23, 2011

Class not found Exception for com.mysql.jdbc.Driver

Hi,

When ever the ClassNotFoundException for com.mysql.jdbc.Driver,
make sure you have added the mysql-connector-java-5.1.17.jar (available on mysql site) in the jre/lib/ext directory.
I was using it with my maven build Spring MVC project and was cursing it unnecessarily.

Happy coding,
Shoeb