Archive for the ‘Java’ Category

maven + netbeans + Java

Friday, August 7th, 2009

Today I wanted to build on of our projects with maven. (As I just deleted my .m2 repo it had to download everything and it took a while.) It went very fast until I started up netbeans that also had this project included. It seems that if you do builds command line and also have netbeans accessing the project this sometimes performs very strangly. You see netbeans keeps scanning the project and maven stopping regularly.
After killing netbeans maven again went blazing fast. After the first build from command finished I restarted netbeans and everything went fine. Pretty bizar if you ask me (however I don’t know the internals of netbeans and maven, maybe there are file conflicts??) Als rememeber that this is on my computer @ work, it’s a windows box with a virus scanner, so everytime you access a file it checks if there is a virus there, this could also have an impact off course.

JavaFX + Oracle

Thursday, July 30th, 2009

A while ago the javaposse opened up a system where we could post questions. A couple of episodes ago they started going through these items. Unfortunately my question didn’t get raised. Reason being that my question got more negative votes then positive votes.

If I look back now, it actually deserved this. My question went something like : “Why did Sun created JavaFX, Flex already plays nicely with Java, why not invent a Java to ActionScript compiler.” (somewhat like gwt but then ActionScript output). Now that Sun got bought by Oracle I’m pretty sure, JavaFX will succeed. At least if Oracle will put their money where their mought is. (Larry Ellison publicly announced his support for JavaFX). Why do I think this will have a big impact on the success of JavaFX. Well pretty simple, take a look at JSF. Oracle was one of the driving forces behind this. There still is room for improvement (isn’t there always). But it’s already a nice framework for building data centric applications.
If you now take a look at the new version ADF 11 and their JSF comonents. Well I haven’t seen many JFS components that are better. I have to admit, I myself am more in favor of none component based frameworks (they tend to be more flexible).
To come back to JavaFX. Currently we still don’t have a DataGrid or something. This is still a big issue, I feel somewhat like when Microsoft first released Silverlight 1. It was nice but not yet usefull. However in the near future I foresee that Oracle will finalize the basic JavaFX components and publish a nice basic DataGrid that will be on par with the Flex Grid(s).

And if all goes well, we should finally see a real Java(FX) component market happening. That’s something I still don’t understand. Flex was way ahead of Silverlight with their framework and wigdets. I recently wanted to compare them again. What struck me was the component market for Silverlight. I already have big players providing very datacentric and rich gui widgets for sale. For Flex I only found Ilog as big player there. I’m still looking for a DataGrid with very powerfull sorting,grouping,… basic stuff. In Silverlight these are already in production (have a look at http://silverlight.componentart.com/#Welcome) For Flex I’m still searching.

As Java is a much more programming driven environment I think these components will show up much faster and probably also in the opensource world. This in my opinion is the big problem of Flex. The framework and language is good enough to do this, but the most guys who know Actionscript have a design background and not a background in enterprise/component development. I really hope Oracle/Sun will release there version 2 really soon so we can see this happening. I’m actually really looking forward to the next couple of years in the Java eco system. We already have a wealth of opensource tools for doing enterprise development (starting from IDE’s,building systems,continuous integaration,testing environmonts,…) if we then would also get a good framework for doing rich gui’s that work perfectly on all platforms (even Linux, still my prefered one) … What does a developer want more?

Groovy and Grails

Thursday, August 21st, 2008

Rails has got a lot of buzz the last couple of years. I myself have investigated it, didn’t write any apps but it looked nice indeed. I wonder why grails doesn’t have this much attention yet. I have read the a couple books on groovy and grails and started my own small project. I have to say I like it, the thing I probably like the most is that you can package it as a standard war file and just deloy it. Another great thing is the fact that you can reuse all the big java libraries that have been released. So you create your reports in Jasper or Birt and just call them from your grails application.

I wonder how they solved this issue in rails. I can hardly imagine they rewrote entire libraries? (maybe they didn’t solve it yet).

Any grails users out there? Any good user groups in Belgium?

Xml Xsl FOP

Thursday, November 15th, 2007

One of the ‘new’ features that was requested in our app was the forwarding of screens to email addresses. We discussed this and adding a simple pdf version of the screen as attachment to the mail was ok.
As at the moment our application isn’t xml based (just Html with custom Javascript,Dojo and DWR) I suggested to first ‘xmlize’ our messages and then convert this xml to a pdf. At previous customers I used Velocity for performing the Xml serialization. But before I suggested this solution I read up on Groovy as I had read somewhere that it has first class support for Xml. And indeed after checking it out. You have a simple MarkupBuilder object that handles a lot for you.


import groovy.xml.MarkupBuilder

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)

xml.Blog(id:"${blog.id}",type:"${blog.type}"){
Content("${blog.content}"){}
}

output = writer.toString()

This small piece of code will generate the following Xml:



Just some content

As I installed the Groovy plugin in Eclipse I get errors when my Xml is false. Not bad at all.
The really nice thing about this is that you just initialize your Groovy engine in Java. You add your Java object (in my example blog) and you can use it as if it was a Groovy object. Then I return the output to my Java code.

Sweet!

As this generates Xml I used a simple Xsl stylesheet to generate an intermediate Xml. So all objects get transformed into this intermediate Xml. This xml gets transformed in to FOP xml and with the nice Apache FOP library I generate a simple pdf.

Another added value is that for changing my pdf or Xml I don’t have to restart my application, so no downtime!!

Alleloeja!!

Tuesday, September 4th, 2007

Hey guys,

I have to admit it’s been a while. But here I am again :D

Today I saw this post on the serverside. And I have only one word for it Alleloeja.

Just look at this piece of code


import com.jinvoke.JInvoke;
import com.jinvoke.NativeImport;

public class Example {
@NativeImport(library="User32")
public static native int MessageBox(int hwnd, String text, String caption, int type);

public static void main(String[] args) {
JInvoke.initialize();
MessageBox(0, “This MessageBox is a native Win32 MessageBox”, “Caption”, 0);
}
}

Why did it take this long to actually do this?

In C# you could do this right from the start. Well beter late than never probably?

Java D&D development

Thursday, June 7th, 2007

At a customer where I work there is a lot of Powerbuilder Development. Powerbuilder is 4GL development environment, you can quickly create simple CRUD applications with the tool. Every now and then we have discussions on it. It’s really quit funny as you can’t compare client-server development with web development or desktop applications vs web applications. The example that is always given is, how long does it take to create a simple master-detail app. Okay with the new Java web frameworks (or ruby on rails) this is also done very quickly.

With my VS.NET 2005 I have a good competitor for beating them in the client-server development area. Java however didn’t stand a chance. My DAO layer can be generated but for then building a simple Swing app, I would lose by a couple of miles. Recently I noticed the Netbeans 6 M9 however. I gave it a go and I was really amazed. I had my database ready and it took me less than 3 minutes to create a simple Master-detail Swing application. According to the documentation I could create a webstart deployement within a couple of clicks. I would say “GO SUN!!”

I do hope they will extend their default swing components palette. Sorry but the ones that are in there at the moment isn’t sufficient. Common people you don’t even have a default date picker component. Well maybe this is because the default java.util.Date in Java is just broken :) But just fix it, I as developer don’t like it that I have to search for these components. Just put them in their. If you compare the VS.NET 2005 controls that are available by default with the Swing components. I can see why we still aren’t that far on the desktop as on the server.

Bejug ??? Why would I ???

Wednesday, May 30th, 2007

Today I received an email from Javapolis. They were starting advertising the upcoming new Javapolis event. On the site they also mentioned there new Javapolis DVD that was available for purchase. I noticed this was an effort from Bejug. So I got interested as I’m a Java developer :)

Now what do you get for paying 100 euro’s to join the Bejug. They have 3 workshops per year and … Well nothing actually. You still have to pay for Javapolis and for SpringOne. Please people explain me, why would I join??? If I compare it to the Linux User Group in Leuven, they have 2 workshops a month and you pay 10 euro’s a month.
I would rather start my own Jug and do the same as the Lug of Leuven. Anybody up for it ?

Hibernate Second Level Cache

Friday, April 6th, 2007

When I have to develop a more advanced web application I tend to prefer java over any other language. Ok I have to admit, I haven’t tried ruby on rails yet, but I’ll wait for Thor to finish his nice plugin for netbeans :)
I just find that java has almost a nice architectural solution for every problem you face (server side that is). That’s also the downside, there are so many solutions out there, that for a new programmer its a bit overwhelming!

That said, I use Hibernate in almost all my projects. (hibernate being an orm and speeding up my development) As you might know Hibernate has caching built in. First level is the cache in your session, and it’s local for you. Second level cache is for performing queries that in most cases return the same result. Now in my case I created the query and passed it a long some parameters. The parameters were offcourse also hibernate mapped objects. I setup the objects to be cacheable and I set the query to be cached. But it still went to the database on every request!?! Strange it should work?!?
So I started digging and after a while found the problem, really stupid (offcourse). I generated my object model using the reverse enginering tools from hibernate. I thought I had overridden all the equals and hascodes of these objects (as you should always do), but it seemed for these objects I passed in as parameters I hadn’t done it yet.

So as I understand, hibernate puts you query in a container, along with all the parameters you pass to the query, and a reference to the resultset. So if you try to perform the query again, he checks if this is already in the map, but because my parameters always returned false when actually business wise being true. He kept on going back to the db. So you see, even the smallest most stupidest things can have a great impact on your whole thing. This case being overriding the equals and hashcode in a small (3 properties) object, made my app lose 0.3 seconds in a lot of requests.

But BUGFIX/ENHANCEMENT has been done :))

DWR

Friday, March 23rd, 2007

In one of my projects the user has to select a customer from a dropdown list. Problem is that the number of customers they have is much to big to prefill. So I used dwr to build a solution. The user has a dropdown from which he can choose the field he wants to query (let’s say street), he than fills in a streetname, presses the button and the list gets prefilled with the list of customers who match.

How does it work. Wel really simple :)

In my backend I have a simple POJO Search with a method getCustomers(String searchField,String searchValue). This calls a service layer, who in turn calls a dao layer,… you know the drill. In the end the method will return a List of Customer objects. I exposed these objects in the dwr.xml configuration file. (that’s it for the java backend stuff) (nice isn’t it :) )

Now the javascript part is also small and handy. I had to include the dwr engine and my exposed object as javascript objects. When the user presses the button this small piece of code gets executed


Search.getCustomers(searchField,searchValue,CustomerCallBackHandler);

When the javascript gets a response back, the CustomerCallBackHandler will be executed. That looks like this


function CustomerCallBackHandler(data){

Where data is an array of Customer JSON objects. This means that in my java Customer object I have the getter/setter getId(),getName(). In javascript I can simply do data[0].id and data[0].name.

Now isn’t that nifty?! :P

/me like

Xsd nillable

Thursday, January 18th, 2007

In one of my current projects we are sending data to another company. Because xml is somewhat the standard for exchanging data these days I wrote a small java app using velocity to generate the xml files. Sure I could have used Oracle’s features to create an xml file but if you use that feature you could just as well give them an ASCII file imho.

So I started by creating the xml schema (xsd). Because some fields can be empty I some nullable fields. And that’s where the issues started. We have some dateTime fields that can be null so I thought spitting out a <date /> tag or <date></date> would do the trick!!! Biep error, after some googling and reading a lot I came to the conclussion that I had to output this : <date xsi:nil=”true”/> . Stupid if you ask me, but hey it now works.

I wrote a small velocity macro that I called:

#macro( xmlempty $value $tag $cdata)
#if ($!value == "" || !$value)
< $tag xsi:nil="true"/>
#elseif ($cdata == "true")
< $tag>< ![CDATA[$!value]]>
#else
< $tag>$!value
#end
#end

Works nice I have to say. The program was straight forward, a file that contains key value pairs. The key was the velocity template, the value was the query. I ran the query, retrieved the ResultSet cursor and while iterating it for every iteration I called upon the template that merged with my UTF-8 filewriter.

What kinde surprised me was the lack of good xsd/xml editors in the opensource. I tried the ones that were bundled with our myeclipse environment but they were more a pain than a gain. (omg lame!) So in the end I installed xmlspy and asked for a testing license. I have to say they have a really good product, but who wants to pay 600 € for an xml editor. People come on, even ms visual studio .net 2005 pro only costs 750. They also have xml support built in, for that I’m willing to pay because of the added value but not for an xml editor. There are only a couple of things I need from an xml editor.

  • xsd code completion
  • Is my xsd valid
  • Why not, with linenumber error
  • Xml code completion using the provided xsd
  • Is my xml valid
  • Why not, with linenumber error
  • Maybe an xpath,xquery and xsl features

That should be sufficient. Hmm looks like a project for the future :)