• Home
  • Events
  • About
  • Java Without the Boilerplate – Project Lombok

    July 26th, 2010

    Project Lombok is a very cool little Java library that aims (and succeeds) in removing boilerplate, meaningless, and uninteresting code from your Java objects. The basic idea is to replace things like getters and setters with simple annotations, and then let the Java compiler generate the necessary bytecode in the .class file so that tools such as Eclipse and the Java compiler have no idea what anything unusual happened. Lombok hooks into the compiler to make sure this happens correctly.

    First we’ll cover some Lombok basics and then show how it can be used with the Canoo RIA Suite (ULC) project and and view generators. This includes details on how to mix Lombok annotated objects with JPA annotations, which you might want to glance at before leaving!

    Update: You do not need ULC to work with Lombok. The two are separate projects.

    Lombok in Action
    So let’s see Lombok in action. Consider this Java class that includes a Lombok annotation:

    OK, so there is an @Data annotation in there. So what? Well, to javac and tools (like Eclipse) this class has getters and setters for all three fields, an equals and hashcode implementation, and a toString method. Eclipse tools still give you autocomplete the Navigator shows the correct methods. Not only did you not have to write (or generate) the code yourself, but you don’t have to see that code when coming back in maintenance mode. The interesting bits of your class are no longer buried in the noise. Consider what this looks like without lombok:

    That’s a lot of code for something so simple. It doesn’t even fit in my browser margins without funky line breaks! Sure, IDEs can generate it for you. But what if something interesting is buried in the equals() method? Or perhaps a setter has a side-effect? You can’t easily see this with the reams of boilerplate typical of Java. With lombok, only the essentials are displayed, so the unique parts of the object will stand out to the future reader. And yes, even using @Data you are free to provide your own implementations for any of these methods.

    Richard Gabriel made this observation when comparing old programs (like MacPaint) to “modern” programs writen in langauges like Java:

    I’m always delighted by the light touch and stillness of early programming languages. Not much text; a lot gets done. Old programs read like quite conversations between a well-spoken research worker and a well-studied mechanical colleague, not as a debate with a compiler. Who’d have guessed sophistication brought such noise.

    Now, with Lombok, sophistication is finally taking the noise away, rather than adding to it.

    Just a couple important details before moving on to a Lombok example that uses Canoo’s RIA Suite

  • Lombok is compile time only. It does not need to be deployed with your app
  • Lombok works with javac and Eclipse. IntelliJ IDEA will not ‘see’ the added methods
  • lombok.jar contains an installer that configures your eclipse.ini file correctly. Be sure to run “java -jar lombok.jar” after you download it (especially for those on 64 bit Linux like me)
  • Lombok with Canoo RIA Suite
    The point of this was to make sure I could use Lombok on my next RIA Suite(aka ULC) project. It’s looks like I can, and you can too. To prove it, let’s generate a RIA Suite project, add a domain class using Lombok, generate the views, and run the application.

    Prerequisites

  • Install Eclipse for Java EE Developers. Make sure that you have for Java EE developers.
  • Install Canoo RIA Suite. Get your download and evaluation key from our customer portal.
  • Install Lombok. Download it and run “java -jar lombok.jar”.
  • Steps
    Here are the steps we’ll perform to get this thing working:

  • Generate a Project using ULC’s Project Generator in Eclipse
  • Add the lombok Jar to your project
  • Create a domain object called Contact and annotate it with @Data
  • Generate the views using ULC’s generate-beans-view in Eclipse
  • Run the app and behold a default, thin client, CRUD application
  • Generate the Project
    The ULC Application Development Guide contains a 10 page getting started tutorial that walks you through the process from starting at zero and going to a deployed RIA Suite application. Really, it is quite simple. You just need to add the Project Generator as an external tool in Eclipse. Although it is a bunch of screenshots, this is a common task for Eclipse users and little can go wrong.

    In Eclipse, click Run -> External Tools > Open External Tools Dialog… and point a new external tool to your “/addon/generators/build-setup.xml” from the RIA Suite install. Your window should look like this:

    0ToolConfiguration

    Now you’ll have the menu entry for Run -> External Tools -> ULC Project Generator, which you should click now. You’ll be prompted for a project name and whatnot, and a sample Contacts application will look like this:

    1GenerateProject

    The script runs and you now have a project on disk that can be run. Just click to File -> Import to import it, navigating to where it is on disk. Your import screen should look like this:

    2ImportProoject

    If it all goes well your project should be open and your Project Explorer should look like this:

    3ProjectView

    Add the Lombok Jar
    We need to add the lombok.jar to the Contacts project, add it to the build classpath, and click Refresh to make sure Eclipse is aware that something changed.

    Copy the lombok.jar to ./Contacts/lib/development directory in your project. Then edit the project properties (right click the Contacts project and select Properties), select the Java Build Path entry, and add lombok.jar as a Jar. Should look like this:

    4AddLibrary

    Create Domain Object
    Let’s add a domain object with JPA persistence to our project. A Contacts application must show a Contact, right? This looks about right:

    Let me explain a few details… The class is marked @Entity so that JPA persistence works. The class will map to a Contact table in the database. The class is marked @Data so that lombok will weave in getters, setters, toString, equals, and hashcode methods. The @Id annotation on the “id” field marks that field as the primary key to JPA, and the @GeneratedValue means the field auto increments. I use the GenerationType.SEQUENCE strategy because I plan on deploying to Google App Engine, otherwise this parameter here is unneeded. Lastly, getters and setters are supressed on the id field by adding @Getter(AccessLevel.NONE) and @Setter(AccessLevel.NONE). If you don’t do this then the view-layer automation of Ria Suite is going to, by default, provide you with edit fields for the id, which you should not do.

    Generate the View Layer
    To generate the view layer, click Run -> External Tools -> “Contacts generate-beans-view”. This tool was installed for you by the Project Generator. Running it generates a simple Create-Read-Update-Delete (CRUD) interface with a table, buttons, and entry editor. You’ll see a couple new classes and property files in your application after you run the tool.

    Run application
    Last thing to do is run the app. Click Run -> Run History -> Contacts (again installed by the project generator), sit back, and behold an application.

    5DeployedApp

    That’s it!

    Next step is to deploy to Google App Engine using that Contacts-copy-to-GoogleApp tool that the generator installed, but that is a blog post (and task) for another day.

    Enjoy!

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Ubuntu Kung-Fu – 10 Best Tricks (and some even work on Macs)

    July 20th, 2010

    By my count, Ubuntu Kung-Fu from Pragmatic Bookshelf is the perfect summer reading book. It’s light, the content is not going to strain your mind the way some computer science tomes will; it’s easy to read, as always with Prag books the writing is conversational and the fonts large; and it’s fun, where else can you read about easter eggs like talking cows and floating desktop fish.

    Admittedly, some of the 315 tips are useless. I’m not sure when I’ll ever use the “cowsay” command to invoke a talking ascii cow, but for some reason I’m glad I know about it. I predict the error output in my Bash scripts is about to get a lot more bovine. Most of the tips are good, though. Of the 315 total tips (less than a page long each), there are maybe 25 dual boot and Windows related tips and maybe 25 more system recovery and troubleshooting tips. It isn’t a comprehensive reference to administration or dual booting, but these tips are still good to keep around in case of emergencies. Someone switching from Windows and still dual booting will find this book extremely helpful. There are also quite a few Gnome desktop tips for how to tune the desktop manager; for instance, how to use drapes to change the wallpaper every morning. But the majority of the book details cool and useful programs and packages to install… stuff I didn’t realize I needed until I found out about it. Normally I prefer printed books, but the best way to read Ubuntu Kung-Fu is by viewing the PDF directly on the computer and having a command prompt open to try the tips as you go.

    If your vision of a great vacation is laying down with a laptop on your belly, banging away on new bash commands and scripts, then this is the book for you.

    Now here are my favorite 10 tips.

    1. Command History Search with Ctrl+R – In a terminal, the up and down arrow shuffles through recent commands on almost any operating system. I had been using grep to search my history (history | grep something) until I found out about Ctrl+R. When you type Ctrl+R, the terminal goes into a matching mode where it tries to guess the entry from your history based on what you type. So type the first few letters of a recent command and the entire thing comes up. This is great, and I use it regularly to expand out “git pu” into a full “git pull origin master”. But don’t get the wrong idea! I still think git is awful.

    2. Running jobs with & and nohup – I discovered & long ago. If you run a program from the command line then the terminal is frozen until the program completes. But if you append & (for instance, “gedit &”) then it launches as a job and you can use the terminal again while your program runs simultaneously. The problem is if you close the terminal then your other program closes as well. Instead use nohup (“nohup gedit”) so that your program does not hang up when the terminal closes.

    3. Use Trash for Command Line File Deletes – There are a bunch of safe alternatives to deleting files using “rm -rf”, and this type lists yet another one. However, I prefer to use the “trash” package. Just run:

    4. gconf-edit – Desktop programs usually have a preferences panel, but not all preferences or settings are available there. The “gconf-edit” program in Gnome looks a little like a Registry Editor and is where all Free Desktop programs must store their configuration settings. Even if it is not in the preferences window you can still access it through gconf-edit. Take a look at what is available for Nautilus and gedit. It should be quite easy to expand your gedit recent files list to be 10 entries long, for example.

    5. Command Line Image Manipulation – There are a whole bunch of command line and batch image tricks you can perform with “imagemagick”. Shrink and enlarge in batch using “convert -resize 50% filename.bmp”, convert formats using “convert -quality 80 filename.bmp filename.jpg”, and sharpen images using “convert -sharpen 0x1 filename.bmp”. Of course, for ascii aficionados like me, there is no beating asciiview. Install these:

    6. Fonts Galore – I agree, Ubuntu fonts just look better, but the author is a little obsessive including 5 different font tips. You can “Make Fonts look superb” by turning on autohinting using a somewhat lengthy process. Or you can just install a whole slew of fonts such as the 465 fonts in ttf-aenigma, the Microsoft imitation fonts in ttf-liberation, or the Comic Sans style fonts in the ttf-fifthhorseman-dkg-handwriting, ttf-sjfonts, and ttf-breip packages. There’s even directions on stealing the Mac or Windows fonts by mounting the alternative OS, copying all the .ttf files locally, and then installing them into Ubuntu. This is probably the only tip that is not 100% legal. Install these:

    7. Command Line Web Browser – I don’t know why but I get a real kick out of the “links” command line web browser. I enjoy the absurdities in life and browsing a text online web from the console seems like one of them. Install it with:

    8. Install all the multimedia codecs you’ll ever need – My family’s favorite baby sitter is the DVD player. When a parent needs a break, there is no joy like popping in a princess or dinosaur movie and seeing a child fall quickly into an animation induced stupor. Peace and quiet at last! Except when the DVD doesn’t play because of missing codecs. Curse you copyright laws! Best to be prepared and just install all of these through Synaptic now:
    GStreamer extra plugins
    GStreamer ffmpeg video plugin
    Ubuntu restricted extras
    GStreamer plugins for mms, wavpack, quicktime, musepack
    GStreamer plugins for aac, xvid, mpeg2, faad
    GStreamer fluendo MPEG2 demuxing plugi
    Finally, be sure to run the DVD playback enabler script: sudo /usr/share/doc/libdvdread3/install-css.sh

    9. See a Quote of the Day Whenever You Log In – I love quotes, so seeing a new one at the top of all my Terminal windows is a real bonus. Just install signify, create a ~/.signify file, and then edit your ~/.bashrc so that the last line reads “signify”. The format for the .signify file is % { quote % | quote % | quote % }. Yes, you read correctly, that is a “% |” delimited list with a “% {” start identifier and a “% }” end identifier, which makes the .signify file qualify as the most ridiculous text file data format I have ever seen. Oh well, just install:

    10. Play Old MS-DOS Games. Hell yes, Bard’s Tale is about to be run! First install “dosbox” and create an empty directory on your disk called “dosbox_c”. Then, using the DOSBox user interface, mount your empty directory by typing “mount C dosbox_c” and then switch to it by typing “C:”. You are now at the DOS prompt. Browse on over to your favorite abandon ware site and start downloading the classics. I suggest raiding http://www.abandonia.com. Install with:

    So that is my best 10. All I have left to say is:

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Griffon Refcard Released, Lead Interviewed

    July 19th, 2010

    Big Griffon news today.

    First, the Griffon Refcard is available from DZone. This is a concise 6-page reference to getting started and working with Griffon. If the only thing you know about Griffon is that it is a Grails and Groovy based framework for building desktop applications, then this RefCard will fill you in with tons more details. And if you’re an old Griffon hack, then you’ll probably still pick up some new tips and tricks.

    Plus, DZone published an interview with Canooie Andres Almiray, the Griffon project lead. You can read the interview here, or click the RefCard below to download the card.

    Anyone interested in Griffon in the Swiss area should come out to Hackergarten on the 30th of July. Several experienced Griffon developers will be present including Andres. And there is free pizza!

    RefCard

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Code Generation on the JVM: Video and Slides

    July 14th, 2010

    Two weeks ago I spoke at the Chech Java User Group (CZJUG) on the topic of “Code Generation on the JVM”. Some of the technologies covered are Lombok, Groovy, GContracts, Spock, AST Transformations, Spring Roo, and other fun stuff.

    The slides are available at: http://github.com/HamletDRC/presentations/blob/master/asttransformations/asttransforms_czjug.pdf

    As a fun aside: my Ubuntu laptop went crazy the night before and I spent all day before the JUG reloading Linux on my vacation. In the end, I had to switch to my wife’s Mac to do the presentation and live coding. I got the Macintosh fully configured and, during the 1st presenter, realized that I had no VGA output on the Macintosh. Oh geez. The final solution was to share my desktop, have an audience member VNC to my wife’s machine, and project the desktop from the audience. It worked and I’m glad I didn’t have to give the whole talk in chalk on the blackboard (although that would have been a fun challenge).

    Enjoy the video!

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Firmenlauf '10

    July 12th, 2010

    When Firmenlauf ’10 was announced, Canoo decided to build a team and to participate again this year. We had great fun last time (see Firmenlauf ’09 part I and II) and the race deadline gave us a goal for our rigorous 30° lunchtime jogging sessions. Also I personally like the team spirit generated by such events.

    Left to right: Andrei, Christian, Roland, Johannes, Hamlet, Günter, Markus and Alexandra

    Left to right: Andrei, Christian, Roland, Johannes, Hamlet, Günter, Markus and Alexandra

    Even though six kilometers is a relatively small distance, a certain fitness is still needed to increase the pleasure factor. Otherwise you are only suffering and this is definitely not what you want to achieve.

    It was interesting to observe how the team organized itself for the training sessions. The participants regularly asked each others to go for group runs. The single shower we have here at the office rapidly became a bottleneck, adding some roughness to the whole story.

    We regrettably had to experience two defects. Hamlet kindly accepted the challenge in the last minute. So at the end we were 8 at the starting line instead of 9 initially announced. At 7pm on Friday the 9th of July the starting gun fired. After a cumulated time of 2:10:34,5 the first group of Canooies composed of Alexandra, Markus, Günter and Christian crossed the line hand in hand, just after the Herzog & de Meuron architects but before another Software engineers company I am not mentioning by name… For a complete results overview, click here.

    Left to right: Markus, Christian, Günther and Alexandra

    Left to right: Markus, Christian, Günther and Alexandra

    The rest of the team composed of Roland, Andrei, Johannes and Hamlet successfully crossed the line as well. Everyone did an incredible job. I can tell you: this year was really hard. It was so hot and humid. A couple of people collapsed (no one from Canoo luckily) and we heard the ambulance at least once.

    More photos could be found on Flickr.

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    css.php