X

Geertjan's Blog

  • June 16, 2006

Reflections on NetBeans at J-Spring

Geertjan Wielenga
Product Manager
I had a really good time at the NL-JUG's J-Spring conference in Ede (in the Netherlands) yesterday. Apart from several really interesting discussions and just the plain enjoyment of demoing NetBeans at the Sun booth (so cool to be able to demonstrate something that is so clearly a good, solid, innovative product; by the way, the best demos I did were the CRUD generation tooling and a guided tour of Ant integration in the IDE... both of these really blew them away), I also delivered my presentation... in Dutch, which was a first for me. I think it went pretty well, and the demo was especially appreciated by those who attended. We basically went through the initial phases of designing the Music NotePad. The take away message was short and sweet: if you take open source Java APIs and Swing components, you can very quickly build an application on top of the NetBeans Platform, using Matisse to pull your user interface together.

Another cool development was that I met Wouter van Reeven from Amis, who used NetBeans IDE 5.0 to present an overview (and some tips and tricks) of the Open Office API. We're going to be working together a bit, me providing a user interface on the NetBeans Platform to access underlying calls to the Open Office API to, for example, create templates and Open Office documents with standardized texts. It's going to be pretty cool, because he's really familiar with the API side, while I'm really familiar with the u.i. side, because the NetBeans Platform and Matisse together make such a strong (and intuitive) combination.

One question I got (from a nice guy called Anthony Goubard) was: "How do I call an Ant target from a menu item?" Well, I talked a bit with Roman this morning and we looked at his Project Packager, which has some examples of this. But an even simpler approach with which to start is found in his early blog entry Hacking NetBeans #2 - Executing Ant Tasks from the IDE. From the perspective of an Action (in this case CallableSystemAction), just create the module project from a template (and create dependencies on the modules Ant, Execution API, and File System API) and then create the Action from a template. Then fill out your performAction as follows:

public void performAction() {
try {
File zf = File.createTempFile("ant-copy", "xml");
BufferedWriter out = new BufferedWriter(new FileWriter(zf.getAbsoluteFile()));
out.write(script);
out.close();
FileObject zfo = FileUtil.toFileObject(FileUtil.normalizeFile(zf));ActionUtils.runTarget(zfo, new String[] {"copy"}, null);
zf.deleteOnExit();
} catch (IOException e) {
System.out.println("IO error: "+e);
}
}

So, in the first line of code, you create a temporary file. You write a String called script to that file. The String has this content, which is defined at the top of the class:

String script = "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>" +
"<project name=\\"Test\\" default=\\"copy\\" basedir=\\".\\">" +
" <target name=\\"copy\\">" +
" <copy todir=\\"c:\\\\mytests\\\\mycopies\\">" +
" <fileset dir=\\"c:\\\\mytests\\\\myoriginals\\" includes=\\"\*\*/\*.txt\\"/>" +
" </copy>" +
" </target>" +
"</project>";

Then the NetBeans API method ActionUtils.runTarget is called and the target that should be run (in this case "copy") is passed to the method. The Output window shows the name of the Ant target that has been invoked. When the VM exits, the temporary file is deleted.

This is of course just a beginning point (you wouldn't want the Ant script to be hardcoded like this and neither do you want to have the directory from/to which you copy to be hardcoded). But, hopefully for Anthony, this is a starting point (at the very least you now know which NetBeans APIs are involved). When I invoked the action, the content of c:\\mytests\\myoriginals was copied to c:\\mytests\\mycopies. (The Action could either be invoked from a menu item, a toolbar button, or a keyboard shortcut.)

One of the other questions I got yesterday was: "Wouldn't it be nice if the IDE would be able to automatically compile a file when the user saves it?" In fact, I just received an e-mail from Anthony, in which he writes the following: "About the discussion yesterday about the person who was asking for the 'compile on save' feature, I was thinking this morning that an 'execute Ant target on save' would be a better feature. This way you allow people to have 'compile on save', 'clean-compile on save', 'deploy on save', 'run on save', 'run-debug on save', 'verify code/xml on save', 'my specific target on save', etc.".

I agree. I think it would be cool to be able to hook Ant targets to commands such as Save. I'm sure something like that would be possible to implement and it would be a pretty useful enhancement, which would also go even further towards integrating Ant into the IDE.

I also spent some time with Johan Compagner from the Wicket project. Cool to finally talk at some more length with one of those guys. Also, Wilfred Springer and Eugene (don't know his surname) from the Dutch Sun organization (although Wilfred now works for TomTom) were good to see again, I'd met them for the first time last year at JFall. And I even bumped into a few of my ex-colleagues from Compuware and SuperNova. I guess developers stay developers forever and ever.

So, as one can see, several interesting discussions came out of the conference yesterday and I'm very glad that I was able to participate in it. Hopefully I'll be there next time too! (Got to come up with a stimulating submission first though...)

Join the discussion

Comments ( 4 )
  • guest Friday, June 16, 2006
    Have you seen this FAQ about creating shortcuts for targets in arbitrary Ant scripts.

    http://wiki.java.net/bin/view/Netbeans/FaqAntShortcut

    I have a folder where I keep Ant scripts. I add that folder to the Favorites window. Then expand the ant script file nodes and create short cuts for them in my IDE.

    For ANT related issues in Netbeans check out:

    http://wiki.java.net/bin/view/Netbeans/NetBeansUserFAQAnt

  • Wouter van Reeven Friday, June 16, 2006
    I totally like the idea of being able to do an "execute Ant target on save" because I was the person who asked about "compile on ave" in the first place. Since I use Maven2 to do my compile/clean/test/deploy stuff, would it be possible to make it possible to attach a custom action to the save action? Or perhaps even attaching any action to any other action? Or would that be stretching the idea too much?
  • Patrick Holthuizen Sunday, June 18, 2006
    It was a joy to watch both the presentations of Wouter and you. I am really looking forward to the possibilities of using Open Office as a report generator, I hope you both have this in scope! ;-)
    P.S. It was nice I was able to see you in real life
  • Geertjan Monday, June 19, 2006
    Hi Patrick, it was nice to see and meet you too! Glad to see you enjoyed the sessions. What kind of reports would you like to make use of (do you like the "Rapid Scam Letter Creator" that I blogged about today)? :-)

    Hi Wouter, there appears to be a way of doing what you describe already. I will blog about this soon!

    Hi 192.18.43.249, thanks for those links, I will look into them soon!

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.