Wednesday, March 31, 2010

How to create a simple Naked Objects Application in NetBeans with Maven

Despite all Marco's painstaking insistence, I have never been a great fan of Maven. I'm not criticizing it, it's just I'm used with the Ant build system embedded in NetBeans: that's why when I last wrote about Naked Objects in NetBeans I sticked to it.

Partially out of curiosity, partially solicited, I decided to give it a try, using this article as a reference. All procedures refer to version 6.8, other versions might be different (I know for sure 6.7.1 is).

The first thing to do is to create a new project:

Then select Maven from the categories tree and Maven Project from the projects list

In the next screen we have to choose the archetype we want to use; under the Archetypes from Local Repository node select the Naked Objects application archetype (4.0.0):

Complete the form with the informations you find in the aforementioned article...

...and there you go; NetBeans (through Maven, of course) has created one project for each pom file, the main one being highlited:

If you check the file section you'll find the recommended directory structure also quoted in the article. This approach might seem overwhelming at first, and probably overkill for just a simple test, but it actually separates different concerns in different projects.

Now we should execute the package phase, which is not defined in NetBeans yet. To bind a custom action to the phase right click the main project and click on Custom - Goals...

In the Goals textfield you specify what goal you want Maven to execute:

You can also tell NetBeans to remember your instructions; for the most curious, this actually creates a nbactions.xml file in the same directory in which the pom resides.

After Maven has finished his stuff all you have to do is run the application. I'm not sure whether there is a different way to do it, but this one works and it's not too weird: switch to the Files view and locate the startup script, right click on it and select Run from the dropdown menu:

Et voila... here's your login form. Enter username and password...

And there you go!

If you read up to here, I owe you a (reiterated) disclaimer: I am not a Maven expert, nor a Naked Object expert, but this tutorial should help the rubber hit the road.

How does this compare to my previous procedure? Even if it was quite hard to come to an end due to my lack of knowledge of Maven, to which I owe the mixed bag of feelings I have about this, I must admit that someone that is already proficient with it gets a faster start than with the Ant approach. The projects structure generated in NetBeans is more complex, but that is not necessarily a bad thing (actually it is, if you are only trying to write a plain vanilla CRUD application that operates on just a few tables).

Which road should you follow? Right at the moment I am not even able to say which one I should follow, so I won't express myself :-)

A very interesting feature is the possibilty to use customized templates in Eclipse to speed up your development; now I'm looking forward to something like this in NetBeans...

To work or not to work...

Today I read this sentence on a website:

E' stato affrontato il tema dell'impatto che l'arrivo di un bambino provoca sull'attività lavorativa delle donne, evidenziando un dato davvero preoccupante: il 27% delle donne abbandona il lavoro alla nascita del primo figlio.

What's wrong with that? I mean, is it so impossible that a woman might feel gratified enough with her baby? Isn't growing a baby the hardest work ever? Why should they feel deprived?

That reminds me that some years ago I saw a big poster for the incoming general election, which said "families don't grow without day nurseries". Why doesn't anybody, at least here in Italy, ever says "families don't grow without a concrete help"? The monthly fee for a day nursery is about the average salary, why should a mother work all day, without seeing her baby - who by the way is tossed around all day since he's two or three months old - just to pay for the day nursery?

Well, many people are forced to. But I always happen to talk to people who earn two or three times as much as I do (and they don't have a mortgage they'll finish to pay when hell freezes over like I do) that complain because they "have" to go to work because money is never enough. I just think they find that being a full time mother is too much for them: my own wife has been a housewife for the last six years or so herself and we've got three beautiful kids, despite all the economic difficulties we might have faced or will have to face. By the way, we need to buy a bigger car, does anybody want to contribute?

Of course I don't think people who make this choice are bad eggs: I'm not against them, nor I judge them. I only don't understand them.

Monday, March 29, 2010

John Williams is the Man Sheet Music

Attention everyone! Mister Tim has published the sheet music of the wonderful Star Wars mix "John Williams is the Man". You can find it as a free download on his site.

And don't forget to visit the Moosebutter site and their YouTube channel.

Saturday, March 27, 2010

Those were the days

Call it naiveness, call it nostalgia, call it whatever you like, but honestly... how often do you see things like these nowadays?

The game has changed, it has become faster, more physical, probabily even more attractive for the audience. But how many Gareth Edwards do we have the pleasure to stumble upon? Look for the underhand pass around minute 9...

Thursday, March 25, 2010

L'amore delle tre melarance

You are all invited to the special reharsal of "L'amore delle tre melarance" which will be held in Paullo on March 28.

More informations on this can be found here. I also slightly suggest that you don't miss this opportunity because one of the promoters is a karate expert and might seek revenge ;-)

Saturday, March 20, 2010

Scotland spoils Ireland plans

With a penalty kick by Parks at the eleventh hour, Scotland destroys Ireland hopes to secure the Triple Crown in their last match at the Croke Park. Regardless of what will happen during the match, many people will be celebrating at the Stade de France tonight; the only thing that remains to be seen is whether France will win the Grand Slam: will England be able to stop their winning strip?

Ireland stuck?

Despite O'Driscoll beautiful try, after the first half the Irish are still losing to Scotland. I'm afraid this year the Six Nations will be awarded to France - obviously they have deserved it so far. What will happen in the clash against England? I'll keep my hopes high...

The dark side of the toast

Ever wondered what Darth Vader had for breakfast? Well now you have the answer:

Unluckily they only ship it in USA and Canada :-( if you live there you can find it here.

Friday, March 19, 2010

Sun/Oracle merger: collateral damages

Maybe the merger will bring some good. Up to now, I have seen Oracle turning their backs on very skilled Sun employees. I heartily hope the trend is going to stop.

Thursday, March 18, 2010

Linux: meet this stranger

One of my colleagues is taking care of the virtualization of our servers; during this process he ran into the linux box which has happily worked as a cvs server for years without even needing a single reboot. Ok I'm exaggerating: when we changed the power lines we did have to turn it off for some minutes.

Now, what does a Redmond sympathizer do when he meets the penguin? he gets lost, of course! Now, I cannot say I know linux like the back of my hand (I don't even know my hand like the back of my hand), but at least I think I can go this far, so I thought to post just a small reminder for everyone out there in his situation.

First things first, can our linux box be virtualized with the conversion software we are using? for this we need to know which distro we're running:
me@mybox:~$ cat /etc/issue
Ubuntu 7.10 \n \l
to get more information we could have checked another file
me@mybox:~$ cat /etc/lsb_release
Next obstacle, the kernel version. For this we have the uname command, with his different switches (uname just says Linux, and I guess even your Windows lovers knew that): -r shows the kernel release, -v the kernel version, -o the operating system. To see them all use the -a switch:
me@mybox:~$ uname -a
Now, about network interfaces... you can use
me@mybox:~$ ifconfig
to get the basic informations, remembering to add the -a switch if you also want to display informations about inactive interfaces. And the default gateway? you can use
me@mybox:~$ route
OMG we are forgetting DNSs... well you can check for nameserver entries in the resolv.conf file:
me@mybox:~$ cat /etc/resolv.conf
To get more or less all these informations gathered together you can check the interfaces file:
me@mybox:~$ cat /etc/network/interfaces

Not very deep, right? nevertheless somebody might find it useful ;-)

Friday, March 5, 2010

How to change Tomcat memory settings

Apache Tomcat comes out of the box with a default configuration that uses just a small amount of memory (64MB). As you can easily imagine, that could not be enough in many situations. If you are using Tomcat as a service on Windows you can easily punch in some parameters that will ease your life using a graphical interface that can be accessed from the Start menu:

This will display the following form:

To increase the PermGen space, i.e. the memory area in which compiled code is stored, you have to add the parameter -XX:MaxPermSize in the Java Options section (I have used 256MB). Switching our attention to Heap space, Initial memory pool and Maximum memory pool, just like the Thread stack size, have a field of their own.

Of course the same parameters can be applied from the command line, which is what you most likely are using if you run your Tomcat on a different OS... if this is the case I'm sure you don't need me to write the detailed procedure here as you probably know it like the back of your hand ;-)

Tuesday, March 2, 2010

How to remove newline chars in SQL

I'm working on the migration from a legacy system to a new one, and the source database is filled with presentation details like newline characters and HTML tags. To get rid of all this stuff (which doesn't belong in there) I used a simple yet effective custom function:

create function removeNewLineChars(@source varchar(150))
returns varchar(150)
return replace(replace(replace(@source, char(10), ' '), char(13), ' '), char(9), ' ')

As the source and target database are Microsoft SQL Server, T-SQL is the dialect of choice.

Let me say it again: presentation details do not belong in data, at least not in an enterprise system. Unluckily, you see it a lot in old applications (and, alas, even in some new ones). You can shoot me for that, but I won't change my mind.