[Tutorial] Log4J with Maven profiles

Here is a quick tutorial to get your hands dirty with the Log4j logging framework.
Log4j allows logging requests to print to multiple output destinations, also known as appenders.
There are several output destinations: console, files, sockets, emails …
First create a Maven project :
mvn archetype:generate
Choose archetype number 109 (quickstart)

Continue reading

[GWT] Reduce the number of permutations

Here is a tip that I found on other blogs and I think is worth mentioning again. I tried it, it reduced the number of permutations from 15 to 3 only (1 permutation for IE, 1 permutation for the FR locale, 1 permutation for the EN locale). That means a compilation time of 1:05.750s instead of 2:02.828s.

In the module file (blabla.gwt.xml), you need to add this line :

<set-property name="user.agent" value="ie6" />

This of course will produce permutations for Internet Explorer 6 only.
There is also another property to define the locales :

<extend-property name="locale" values="fr" />

So this will generate 2 permutations only : 1 for IE and 1 for the FR locale.

Here is a list of user agents :
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/UserAgent.gwt.xml

Java puzzlers

This week I attended the very first and very well organized conference What’s Next ? in Paris and one of the speakers was Neil Gafter, co-author of the book “Java™ Puzzlers: Traps, Pitfalls, and Corner Cases” (2005).
He shared with us 2 or 3 puzzlers which I will share here too :
Question 1) What will the following program print ?

import java.util.Random;

public class Rhymes {
    private static Random rnd = new Random();

    public static void main(String[] args) {
        StringBuffer word = null;
        switch(rnd.nextInt(2)) {
            case 1: word = new StringBuffer('P');
            case 2: word = new StringBuffer('G');
            default: word = new StringBuffer('M');
        }
        word.append('a');
        word.append('i');
        word.append('n');
        System.out.println(word);
    }
}

Continue reading

Eclipse Dali vs Hibernate Tools

The process of mapping tables to entities is greatly simplified with tools like Eclipse Dali and Hibernate Tools, both available as Eclipse plugins. It avoids mapping them by hand, which in my opinion is prone to mapping errors and takes more time. And I really do not see why one should map them by hand when great tools like Eclipse Dali and Hibernate Tools are available.
In my book, I describe the use of the Eclipse Dali plugin to automatically generate the entities.
Lately I have also used Hibernate Tools and I have already noticed a few differences between these two tools.
I am going to list some of these differences.
Continue reading

[GWT] Table with pagination and one sortable column

I just added a very basic GWT project to my github account to display a table with pagination and one sortable column.
The code is mostly based on the official GWT tutorial :
http://code.google.com/intl/en/webtoolkit/doc/latest/DevGuideUiCellTable.html

I basically just added the SimplePage element to handle pagination :

SimplePager pager = new SimplePager();
pager.setDisplay(table);

Source :
https://github.com/longbeach/MyFirstCellTable
Demo :
http://tableaupagination.appspot.com/

How to rollback a transaction in GAE

This has nothing to do with JPA.
I was trying to deploy a GWT webapp to GAE when I suddenly got an error.
As a remedy, i got the message :
"java.io.IOException: Error posting to URL: https://appengine.google.com/api/appversion/create?app_id=tableaupagination&version=2&
409 Conflict
Another transaction by user xxxxx is already in progress for this app and major version. That user can undo the transaction with appcfg.py's "rollback" command."

After digging into Google a bit, I found that the way to launch that rollback command under Windows is the following :
1) Figure out where the Google App Engine Java SDK directory is.
In my case, it’s under the Eclipse plugins directory :
D:\Dev\eclipse-jee-helios-SR1-win32\plugins\com.google.appengine.eclipse.sdkbundle.1.4.2_1.4.2.v201102111811

The bin folder contains the appcfg.cmd command.

2) Under a DOS command prompt, go to the workspace folder of your project and launch the following command :
"D:\Dev\eclipse-jee-helios-SR1-win32\plugins\com.google.appengine.eclipse.sdkbundle.1.4.2_1.4.2.v201102111811\appengine-java-sdk-1.4.2\bin\appcfg" rollback war

After that, you can try to deploy the app again and it should work.

Links :
http://code.google.com/intl/fr/appengine/docs/java/tools/uploadinganapp.html
http://code.google.com/intl/fr/appengine/docs/java/gettingstarted/uploading.html

Code for the book is now on GitHub

I finally added the code for the book “Les EJB 3 (avec Struts 2, JSF 2, JasperReports 3, Flex 3)” to GitHub.

To grab it, you have 2 options :
1) use GIT and type :
git clone git://github.com/longbeach/VenteEnLigne.git
2) use SVN and type :
svn co http://svn.github.com/longbeach/VenteEnLigne

As a matter of fact, and surprising as it might sound, you can use SVN to grab code from GitHub 🙂

Assembla

I found another cool website that offers free workspaces that can be managed with Subversion, Git, Mercurial etc…
Of course it also offers various plans with monthly payments.
Anyway, I just put an empty project in my workspace. Check out the screenshots :
Continue reading

[Tutorial] Create a Web Service with Apache CXF and JBoss 6

I have recently started studying Apache CXF, the open source web service framework. I am familiar with developing Web Services using EJB 3, Axis or Glue. But not with CXF. Until now.
CXF is a mix of two projects : Celtix and XFire, which explains the name CXF.
It provides support for the JAX-WS, JAX-RS and JAX-RPC specifications.
Developing Web Services using CXF and JBoss is quite easy. The only annoying part is to figure out which JARs libraries
to include in the classpath and which JARs libraries to exclude.
Continue reading

CanIuse.com and fmbip.com

Here are two very useful sites :
http://www.caniuse.com/
Like it says, it shows “compatibility tables for features in HTML5, CSS3, SVG and other upcoming web technologies”.

Another one is http://fmbip.com.
It displays a table showing exactly what browser you’re using and what CSS3 & HTML5 capabilities the browser supports.
http://fmbip.com/litmus displays test results showing when you can start to use specific HTML5 & CSS3 functionality.

Very handy resources for developers !