Archive for the 'Java Frameworks' Category

Wicket Phone Book and Maven 2

This evening I tried to download and setup the wicket-phonebook example in Eclipse. The application uses Maven2, something I have not had a lot of experience working with. In the root directory of wicket-phonebook, there is a script called Eclipse.sh which configures everything as an Eclipse project. It also downloads into the Maven2 repository almost all the dependencies.

However, there are two steps that are not done:

  1. Set up the M2_REPO environment variable in Eclipse
  2. Download and install JTA

For the first, I found the following command:

mvn -Declipse.workspace=
 eclipse:add-maven-repo

And for the second problem, I found the answer on JUGPadova website. In short, the problem has to do with Sun’s licensing of some of their J2EE jar files. Once I downloaded the JTA.1.0.1B.jar file, the following command put it in place and took care of all remaining errors in my Eclipse project.

mvn install:install-file \
  -Dfile=./jta-1_0_1B-classes.zip \
  -DgroupId=javax.transaction \
  -DartifactId=jta -Dversion=1.0.1B \
  -Dpackaging=jar

Use Hibernate Paging when processing lots of objects

At work right now I have been trying to solve an OutOfMemoryException in a Java web application. The app exposes a bunch of web services. All of which can end up processing a large collection of objects returned via Hibernate. All of which can also keep a Hibernate session opened for a very long time.

So far, the solution we have found is to use paging along with releasing the session before doing another Hibernate query. We do the query, get back a collection of objects and iterate over that collection, processing each one in turn. Then, when we are done, we close that session, open a new one and get another collection of objects.

Hibernate makes this very easy to do:

public Collection find(int page, String hsql) {
    getSession.close();
    getSession();
    int page_size = 25;
    query=session.createQuery(hsql);
    return query.setFirstResult(page * page_size)
            .setMaxResults(page_size).list();
}

I have not supplied implementations for getSession since this depends on how you are working with Hibernate (i.e., Spring or HibernateUtil class).

Wicket it is

For my open source Java app, I have decided to go with “Wicket.”:http://wicket.sourceforge.net/ My decision really comes down to two things; 1) I like the idea behind Wicket, I like the website, and I like that it is suppose to be fun to program with and 2) I have to learn something so why shouldn’t it be Wicket. And getting a comment from one of the developer’s didn’t hurt either.

Plus, with working at ThoughtWorks, I figure I will have plenty of time to learn other frameworks, so why not learn one of the up and coming ones. At least this way, if I am ever put on a project at the beginning, I can argue for or against its use intelligently.

Thanks to all the people who offered their suggestions. So now I just have to get my butt in gear and start coding.

What Java web framework to use?

I have a very “neglected open source project”:http://code.google.com/p/teamdocs/ that I am going to start working on again. I am going to rewrite it from the ground up using Hibernate and JPA or Hibernate Annotations (I am not quite sure yet), probably Spring, and some web framework. The problem is that I can’t pick a framework.

I was going to go with “Wicket”:http://wicket.sourceforge.net/, but I am not sure I want to go with something that is component based and I can’t really find any good tutorials. There is suppose to be a book coming out, but I don’t really want to wait. On the other hand, it is supposed to be fairly easy to learn and fun to work with.

I have also been thinking of using “Struts 2″:http://struts.apache.org/2.x/. Yesterday, I found a nice “120 page tutorial on getting started”:http://code.google.com/p/sq1-struts2/ with it that would be a huge help. Struts is the 800 pound gorilla when it comes to web frameworks and Struts 2 is suppose to be easier to learn and work with.

Then there is Spring MVC, Tapestry, Echo2, Trails, Stripes, JSF, etc, etc, etc.

Anyone have any suggestions on which one to learn and use? My only requirements are that it be fairly easy to learn, has very good tutorial and documentation support, being actively developed, and is not Struts 1.x, and has some IDE/tool support.