Skip to content

Blogs

JBoss AS7 for Spring Developers

Java TV - 1 hour 7 min ago
This video shows you how JBoss AS7 with its new architecture and a new set of features provides an ideal environment for developing and deploying Spring applications. There are multiple ways in which a Spring developer can benefit from JBoss AS7. You can either use it as a generic Java EE 6 application server and stay up-to-date with the latest enterprise Java specification. Or you can take advantage of features which are unique to JBoss AS and provide a competitive edge. This video covers both angles.
Categories: Blogs

Sneak preview: Navigating from C++ code to Protocol Buffer declaration – in Eclipse

Alex Ruiz's Weblog - 9 hours 5 sec ago

One of the most popular features of protobuf-dt is its integration with protoc, the Protocol Buffer compiler. When this feature is enabled, protobuf-dt invokes protoc to generate Java, C++ or Python code when a .proto file is saved.

A fairly common feature request is navigation from generated code to its declaration in the .proto file. For example, navigating from a generated C++ class that extends ::google::protobuf::Message to the actual declaration of the Message element in a .proto file.

I started working on this feature a week ago and now I’m happy to show off some progress. The following movie demonstrates the following:

  1. How to enable and configure protobuf-dt’s integration with protoc
  2. How C++ code gets generated after saving a .proto file
  3. How to navigate from the generated code to the protocol buffer declaration

Under the covers

To accomplish this code navigation, I created an Eclipse plug-in that acts as a bridge between CDT and protobuf-dt. Navigation from generated C++ code to its declaration in a .proto file is as easy as right-clicking on a C++ element and selecting the menu “Open Declaration in .proto File.”

Under the covers, the bridge plug-in does the following:

  1. Finds the C++ AST node enclosed in the current cursor position in the active CEditor
  2. Derives the qualified name and type of the proto element from the qualified name and type of the C++ element found in the AST
  3. Asks the Xtext index for the URI of the proto element that has an equal qualified name and type
  4. Asks the Xtext index for the closest match, if the previous step failed
  5. Asks Xtext to open and select the element under the found URI

Of course, this a over-simplified explanation. For more details, the source code of the bridge can be found here.

Challenges

Creating this plug-in was not too difficult. I think the biggest challenge is reverse-engineering protoc to figure out how navigation from generated C++ code to .proto files should be done. A good example is nested Protocol Buffer messages. When a nested message is compiled to C++, protoc creates a top-level class using underscores in the name to concatenate the names of its ancestors.

For example:

Both the messages Outer_Message.Inner and Outer.Message.Inner will generate a C++ class with name Outer_Message_Inner. In this case, there is no single path for navigating from C++ to Protocol Buffer. Currently we identify this ambiguity and select the first match only. I’m thinking about displaying a dialog showing all the possible options and let the user chose the Protocol Buffer element to navigate to.

Another thing I haven’t figured out is how to enable this menu only for files with names ending with “.pb.h.” Here is how I define the menu in the plug.xml file:

<extension point="org.eclipse.ui.popupMenus">
  <viewerContribution
      id="com.google.eclipse.protobuf.cdt.cEditorPopup"
      targetID="#CEditorContext">
    <action
        class="com.google.eclipse.protobuf.cdt.ProtobufCdtExecutableExtensionFactory:com.google.eclipse.protobuf.cdt.actions.OpenProtoDeclarationAction"
        icon="icons/pb.gif"
        id="com.google.eclipse.protobuf.cdt.openProtoDeclaration"
        label="Open Declaration in .proto File"
        menubarPath="group.open"
        style="push">
     </action>
   </viewerContribution>
</extension>

Any suggestions or hints are appreciated! :)

Road ahead

I only scratched the surface of what can be done to integrate C++ and Protocol Buffers in Eclipse. There are still a lot of things to do. In the case of C++-to-Protocol-Buffer navigation, I still need to:

  • Figure out how protoc handles letter cases and C++ keywords in Protocol Buffer element names
  • Implement message field matching by both qualified name and type (currently matching is done by qualified name only)
  • Support navigation for the rest of Protocol Buffer elements: enum literals, groups, rpcs, services and streams

There is also other functionality that would be really useful to have:

  • Cross-language refactoring: update all references in generated code when a Protocol Buffer element is renamed.
  • Find usages of Protocol Buffer elements in generated code. This functionality can also have other interesting uses. Eclipse can warn a user, before deleting a .proto file, that there are dependencies on the code generated from that .proto file.

For now I’m concentrating on C++. Java support will come next.

Summary

In this post I have show you some of the upcoming functionality in protobuf-dt. Navigation from generated C++ code to its declaration in .proto files in Eclipse is a handy feature that is finally being implemented. It is not complete yet, but I expect to have a “beta” (or “testing”) release pretty soon.

Feedback is always welcome :)

(Image taken from Calsidyrose’s flickr stream under the creative commons license)
Categories: Blogs

Ultra low latency Event Store

Vanilla Java - 13 hours 17 min ago
Overview
There are two basic libraries for managing data in Java, JDBC (for connecting to database) and JMS (for messaging). For some use cases you ideally want both, and you want it to be very fast.

HistoryThis is a redevelopment of a previous project HugeCollections The project is still on hold because its too complex IMHO for what it does. This library is lower level and much simpler to understand. It may become the basis for the higher level HugeCollections library.

The Java Chronicle LibraryThis library attempts to provide ultra low latency, high throughput, persisted, messaging and event driven in memory database with random access to previous messages) The typical latency is as low as 16 nanoseconds (between processes), supporting throughputs of 5-20 million messages per second.

Technical Features
  • It uses almost no heap with trivial GC impact regardless of size, 
  • It can be much larger than your physical memory size (only limited by the size of your disk). and can be shared *between processes* with better than 1/10th latency of using Sockets over loop back. 
  • You can attach any number of readers, including tools to see the exact state of the data externally. e.g. I use; od -t cx1 {file} to see the current state. 

It can change the way you design your system because it allows you to have independent processes which can be running or not at the same time (as no messages are lost) This is useful for restarting services and testing your services from canned data. e.g. like sub-microsecond durable messaging. 

Modes of useThe library can be used in two mode. Either as an event driven persisted journal, or as a re-writable random access store.
The main limitations are that it only designed for one writer, and "extracts" or records cannot be made larger once they are written.

Download or Browse the Java Chronicle Library
Categories: Blogs

Setting JavaFX 2 Runtime At Start (And Solving "Unable to read ../rt/" Problem)

Adam Bien's Weblog - Mon, 02/06/2012 - 05:07
If you run "java -jar killer-app.jar" on a machine where JavaFX SDK was installed with a simple "unzip" (like a Mac), you will get the following error:


Unable to read ../rt/lib/jfxrt.jar
Unable to read ../../../../rt/lib/jfxrt.jar
Unable to read ../../sdk/rt/lib/jfxrt.jar
Unable to read ../../../artifacts/sdk/rt/lib/jfxrt.jar

Because the Java FX launcher does not know where to find the runtime, it falls back to the default location.
To solve this problem, just pass the system property: javafx.runtime.path with the JavaFX SDK location at start:

java -Djavafx.runtime.path=[THE UNZIPPED JAVA FX SDK]/rt -jar killer-app.jar
*NEW* Real World Java EE Night Hacks - Dissecting Best Practices ...and the bestseller Real World Java EE - Rethinking Best Practices

Java EE Bootstrap Workshop [Airport Munich]
Categories: Blogs

From 0 to Node.Js/Jasmine/CoffeeScript in 10m

Context/Background
I wanted to get started with Node.js, Jasmine, and CoffeeScript. How to go about it in an Ubuntu system? For some reason installing node.js via sudo apt-get install nodejs (full instructions) didn't work for me. I overcame this by locally compiling it, but then other issues came up as I moved on to Jasmine. It took some trial-and-error time but eventually I zeroed in on the solution. A key part is the installation of npm (a package manager for Node.js).

Starting Point
You have downloaded Node.js source code (here, node-v0.6.10.tar.gz) into your ~/Downloads directory.

From .tar.gz to Jasmine...
mkdir -p /tmp/installation
cd /tmp/installation
tar -zxf ~/Downloads/node-v0.6.10.tar.gz 
cd node-v0.6.10/
./configure
make
node -e "console.log('Node.js is up')"
curl http://npmjs.org/install.sh | sudo sh
sudo npm install jasmine-node -g
cat <<"EOF" > app1.spec.js
var app = require('./app1.js');

describe("my app", function() {
  it("greets you", function() {
    expect(app.helloWorld("Martin")).toEqual("Hello, Martin");
  });
})      
EOF

cat <<"EOF" > app1.js
exports.helloWorld = function(s) {
  return "Hello, " + s;
}
EOF 

jasmine-node app1.spec.js

... to CoffeeScript
sudo npm install -g coffee-script

cat <<"EOF" > app2.spec.coffee
app = require './app2'

describe "my app", -> 
  it "greets you", -> 
    (expect app.helloWorld "Martin").toEqual "Hello, Martin"
EOF

cat <<"EOF" > app2.coffee
exports.helloWorld = (s) ->
  "Hello, " + s;
EOF

jasmine-node --coffee app2.spec.coffee

Final thoughts
This post's goal is to reduce setup time/learning curve such that others can start using these (great) tools right away. As a Node.js noob, I didn't even know that npm exists. I also found it difficult setting up my first toy programs: a Node.js program, a Jasmine spec, a CoffeeScript program, and a Jasmine/CoffeeScript spec. There are syntactic issues and framework issues (such as: Node's require() and exports thingy) which you need to get exactly right  in order to make the pieces fit together. An out-of-the-box running sample - which is what this post tries to provide - can mitigate much of this pain.

I also found it difficult to find good web-pages discussing this process. Thus, for the common good, I will put a few keywords to help future Noobies find it: jasmine node.js coffeescript Ubuntu npm spec installation setup getting started hello world program.

Categories: Blogs

JSP and Servlet Tutorial 02 – First Servlet

Java TV - Thu, 02/02/2012 - 20:27
This tutorial episode shows how to use Eclipse wizards to create a Dynamic Web Project (part 1). You will then create and run your first Servlet (part 2). Video Producer: http://javabrains.koushik.org
Categories: Blogs

Modeling, with Tools/Without

Rob Williams' Blog - Thu, 02/02/2012 - 17:31

It‘s totally crazy that in 2012 there are so few good choices for modeling tools. I got encouraged for a minute today when I found a thread on Stack Overflow that included a bunch of products and I found out about SparxSystems‘ System Architect . Got all the way to downloading the trial version when I saw that it was an exe. Yes, folks, Windows only.. in 2012. Unbelievable. Hilarious that these guys are selling tools for doing MDA. Guys, where is your PIM? Oh, yeah, you don‘t have one (clearly). Your codebase is already a PSM (platform-specific model).

What are modeling tools for? Sure, we could set our sights lower than MDA‘s answer: logical representations of both requirements and specifications, and a generative mechanism for platform-specific versions. My desire for modeling tools is to speed the process of figuring out how to do very complex models. But many tools are pictures only to make people feel better about the fact that someone has thought about something. I used to be driven toward the idea of reversibility way back in the 90s when I was using Togethersoft, but I am not so much into that anymore. I think MDA is too ambitious and is bound to produce very robotic solutions. Guess what I am saying is I am interested in all the pieces, but more interested in using the images to flush out ideas and then a generative layer to get much of the boilerplate done (a la Roo and Forge). And then, the ability to support some basic metaprogramming notions.

I can't see myself running an emulator to get to use Sparx' tool. Which made me go back and take a look at where the Eclipse Modeling Tools are at. The answer is everywhere. That could be a good answer, but if you just go to the page and start reading, its a treatise in what everyone complains about on the Java side: a sloppy dog's dinner of every possible idea cooked to some uncertain degree of doneness. Seriously, this is the page here .

I have written plugins before (for eclipse), and used EMF before (with JET). I have Ed Merks‘ books and generally like EMF a lot, but there was never much tooling with it in the beginning, and now, if this heap has some in it, I fear that ferreting it out will take the better part of a year.

I have been learning After Effects lately because I had an ah ha moment recently where I realized that we jump too quickly into requirements even (we all knew that about specs), and immediately run to get busy before we have probably cemented their predecessor. What is that? The vision? Well, vision docs are a good idea, but I think there is something else that is missing: a conceptual understanding. It‘s not just the abstract types you intend to use, or the couple ways someone‘s going to use your app. It‘s how your app plugs into the world and how it will appear to someone who will attempt to use it. While I was thinking about this stuff a friend of mine gave me a book of Occam‘s philosophy. A guy who has been reduced to a philo sound bite. Turns out he was a conceptual philosopher. I have said this 20x before, but programming could benefit immensely from a greater embrace of philosophy. This is not just answering the question ‘what should this do?‘ It‘s answering questions like ‘how will someone figure this out?‘ or ‘how can we entice people into this part of the problem while making their labors feed this other side of the model?‘ For example, consider Amazon. That company owes 90% of its success to its reviews. If you went to people in 1995 and told them ‘the kind of retail online will be the one who makes it possible for me and everyone else to write sometimes 10 paragraphs on what we did and didn‘t like about the product,‘ 90% of the responses would have been akin to Ballmer gleefully (and stupidly) exclaiming ‘nobody is going to pay $500 for a phone!‘ Is this systems thinking? (yes) heuristics? (yes) and also evolutionary/emergent/complexity-oriented? (yes). A mere smattering of these influences, if you allow them into your mind, make our ‘tools‘ look like tinker toys.

Finally, the other thing I am obsessed with deserves the final spot in this chain of thoughts: reactionaries who think they are revolutionaries . Some amount of reaction is required of course, but think about the degree to which most tooling has been born of frustrations with the stupidity of the current state of affairs. I remember when Sun first introduced EJB, with all of its stupid requirements for XML files, etc., and the toolers got all excited that no one would want to produce that junk by hand, so they could add generation of it to their tools and that would justify a G per seat for their suites. Remind me, Fellas, how did that moonshot go? Oh yeah, it crashed and burned and birthed the biggest reactionary revolutionary of the Java world: Rod Johnson. When I watch the Forge demos or look at Spring Roo, I have to laugh (especially when the Mentos music plays on the Forge ones). Guys, go make a new project in Xcode. It takes about a minute and a half. Yeah, that‘s right, you don‘t have to pick amongst 20 versions of Hibernate (only to find out that 4 is incompatible with Seam 2 3 days later), and you only have one test runner, but you can customize things. I added OCHamcrest to my projects, and OCMock now. While I‘m at it, coming off of days of sifting through the crash site engendered by the innocent need to move Jenkins and Nexus, seriously, the situation with the management of dependencies in Java has gotten to the stage where it‘s like that fire that started in the coal slough pile in Kentucky that‘s been burning for 10 years, or the state budget of California, which no one really has been able to even feign command of for 3 decades.

If there‘s one commandment that has stood the test of time in the software engineering world, it‘s the one laid down by the brilliant Ivar Jacobson: use cases must be the central focus. We have convinced ourselves that we have to have all these things because we were suffering with what we had. A hot dog is a feast to a starving man. Having failed to really deliver on the promise of serious end-to-end modeling, we have comforted ourselves with these rapid fab demonstrations of cutting through the sheets of ice. When it obviously makes more sense to not get yourself stuck in the first place.

Categories: Blogs

Eclipse Community Awards voting open. Please vote

Java and Eclipse News - Lars Vogel - Thu, 02/02/2012 - 14:02

Just a small reminder, the Eclipse Community Awards is currently open for voting. Please vote: http://eclipse.org/org/press-release/20120130_awardsvote.php

I’m also nominated, as Eclipse Top Newcomer Evangelist :)

flattr this!

Categories: Blogs

A Mini/Lion Server Migration Story

Rob Williams' Blog - Wed, 02/01/2012 - 22:31

A lot has been written about Lion Server. First there were a lot of people who came running into the room screaming about how the interface to it had been dumbed down to the point of useless cartoon. Then there were a bunch of reviews saying the idea of the server has been simplified, finally, after all these years. The truth, as usual, lies somewhere in between. Let me make a quick point here though: in a world that should clearly regard complexity as one of the chief things to try to learn and understand, and develop techniques for intelligently reducing, further, where everywhere our worst problems scream out that complexity has beaten back would be simpletonian conquerors, you would think that people would at least show some interest in this. But, sadly, the world is still happy to try to use complexity as a cloak. The experts do everywhere (doctors, chefs, programmers, admins, filmmakers) and when someone comes along and tries to reduce it, they are often met with a thankless lot of being harangued by said experts. Why? Because their simplification didn‘t account for every stupid thing the expert needed (Lion Server, Final Cut). The key is that there has to be a sufficient desire on the other side to make the simplifying party continue on. Not sure whether Apple will (they gave up on iWeb, which was a pretty astounding tool for making websites that could be made an absolutely amazing one with a little TLC and someone who could do some abstracting). I hope they do.

When everything was said and done, the frustrations afforded my cruise from mini 1 to mini 2 that went on the Apple scorecard as debits were minute compared to the ones from my trusted open source java tools. I have whine mercilessly in the past about how Jenkins/Hudson stupidly piles up tons of ancient, useless builds and they are about as easy to get rid of as lice in a population of soldiers stooped in wet foxholes. That came back again. I love Jenkins, but what a stupid way to behave. My first law of computing is ‘thou shalt not make a mess,‘ and Jenkins fails miserably in that regard.

Moving the jobs themselves was pretty easy. The main complication came from the fact that at some point I generated ssh keys for the _appserver user (a hidden user on OS X) and figured out that they had to go into /var/empty, but I could not find where I learned that from (should have blogged about it). This time I will go ask a question on StackOverflow. For this venture, I just moved those keys over to the new server and the build worked (the keys were already installed in the GitHub owner‘s account).

Moving Nexus was no picnic, but a great thing came out of it. When I first moved to Maven way back in 2006, I setup a corporate repo that was served through WebDAV and used certs that each dev had to install into their cacerts file. Sounds simple, but the amount of stupid timesuckery that caused over the years made a huge ant file that pushed binaries around almost look tasty. But Ant (model-less) was so dumb I never put the car in reverse. I used Archiva, but that was a PITA, and really was just a good way to have a ui to stick artifacts into repos (since many of them didn‘t have maven repos). When I found Nexus, thanks to Mert , I was hoping I could have it give me all 3 things: public repos proxied, my own collection of 3rd party crap that didn‘t need to be protected, and my private repo. Took the first 2 and ran at first. Finally went back for the 3rd while moving it this time and got that to work. Ah… ! Thanks Nexus!

Meantime, my couple little nits on moving Nexus:

  • the config files are cleanly cordoned off in a dir and are even readable XML
  • the LDAP configuration page is pretty clear and easy (did a StackOverflow Q and A About Configuring LDAP, but getting settings.xml setup for access to private repos is not clear and configuring groups not clear either
  • moving repositories was pretty easy, but how hard would it be for this thing to have a way to make a repo dump and then restore it into another repo?? I didn‘t want to take all settings because for instance the LDAP server is obviously different..

Anyway, stupid amount of time, but ultimately got there with improvements. My suggestion on the Nexus docs is they are way above average, but, they should think about making some wizards in the app. The problem with apps like this that are completely wizard free is that you end up looking like Microsoft‘s interface for Exchange Server (the way it was when they first launched): a huge maze of tabs with interdependencies that you don‘t know about.

The last thing in moving to the new i7 mini with an SSD and 8 GBs of RAM is to separate out the builds into one build that runs only fast tests that have mocks for anything outside and then have the tests that verify that outside dependencies are still the same run occasionally from another job.

Nits on Apple‘s side are that the migration tool failed 2 or 3 times then we just moved things manually but that mostly worked and was not terribly difficult. We ended up making new user accounts. The wikis migrated which was cool. I thought the Lion Server Wiki was supposedly more powerful, not seeing that so far. Anyway, on the whole a remarkable package. Linux has been going 20 years. I hope Apple will just drive a spike through the idea that you need an admin to setup and then nurse a simple server. It‘s time…

Categories: Blogs

Feb 2012 Challenge of the Month – Eclipse 4 Book

Java and Eclipse News - Lars Vogel - Wed, 02/01/2012 - 08:45

Challenge: Eclipse 4

This month challenge will be to get the first version of my Eclipse 4 book out. I’m working on this now for a while and I think I should put a first version out so that people can learn better about the amazing Eclipse 4 platform capabilities.

I’m very busy this month so I hope this works out.

Retroperspective for last month challenge:

Last month I switch completely to Linux / Ubuntu. First of all: Thanks to all for their support to my questions in Twitter and Google.

Ubuntu 11.10 is amazing. Using Linux feels like coming home to me. As a student I used Unix (Solaris) and SUSE Linux a lot. Later at my first job I worked with HP-UX.

Ubuntu gets everything right (for me). The shortcuts are at the right position. It detects my devices without problems and I truely enjoy Unity (after I tweaked it a bit).

It is so nice to be able to run find . -name “*.xml” -print0 | xargs -0 grep -i “stuff I search” and get immediate results. Also using the Git command line feels so better, compared to using it under Windows.

I also also extremely surpised that Ubuntu supported my iPod directly. I just connected it, started Banshee and could maintain my playlists and put music on the iPod. Also the Amazon MP3 store integration is amazing. Much better for me then iTunes on Windows as I buy my stuff at Amazon.

I would like to thank Marcelo Módolo for his tips on Ubuntu. He told me that I can mount FTP accounts in the file explorer. That is a huge time saver for me.

He also gave me a hint to Shutter an awesome screenshot tool. I was kind of afraid that I would miss SnagIt but shutter is even betten IMHO. I was afraid that I would miss SnagIt, but Shutter works even better for me.

Marcelo also gave me a pointer to How to change tooltip background color in Unity to make the Javadoc view in Eclipse readable.

I also had some issues with Ubuntu

I got really frustrated with the Alt+tab key. But after some initial fighting with Alt+tab I learned that if I hold it over an entry with multiple windows (or press the Arrow-Down key) that I can select between multiple windows of the same application.

I also had a problem with the Touchpad. It seems to get activate quite easily. So I wanted to deactivated it but I still wanted to have the Touchpoint avaiable.
Dariusz Luksza
gave me the following working tip via Twitter:

synclient TouchpadOff=1

I later got the tip from Thilo Wetzel and Martin Riedelon G+ that the shortcut Fn + F8 also works.

The other annoying things was that the Shift+CTRL+Up shortcut of Eclipse was caught by the Ubuntu system. This shortcut was not listed in the standard shortcut (how can you make fixed shortcuts?). I found an answer to that on the Ask Ubuntu Website – How to turn off the alt-shift-uparraw key.

Also the fading launcher was annoying at first, but I used ccsm to fix its position. It also took me a while to get used to the menu on the top (like the Mac has it). I’m looking forward to HUD in Ubuntu 12.04.

Summary:

I will not switch back. Ubuntu rocks. And just out of completely in the hope to avoid any: “Try a Mac” comments: I once tried using a Mac for a month and I didn’t like it.

Thanks everyone for there help with using Ubuntu. I can really recommend Ubuntu, it is Linux done right in my opinion.

flattr this!

Categories: Blogs

Functional Thinking for Java

Java TV - Tue, 01/31/2012 - 13:31
This video shows you how to transition from a Java writing imperative programmer to a functional programmer, using Java, Clojure and Scala for examples. It takes common topics from imperative languages and looks at alternative ways of solving those problems in functional languages. As a Java developer, you know how to achieve code-reuse via mechanisms like inheritance and polymorphism. Code reuse is possible in functional languages as well, using high-order functions, composition, and multi-methods. Expect your mind to be bent, but you’ll leave with a much better understanding of both ...
Categories: Blogs

Tomcat On Steroids (on Java EE 6) = TomEE--A Server Smoke Test

Adam Bien's Weblog - Tue, 01/31/2012 - 08:45
Apache TomEE is an opensource, Java EE 6 WebProfile certified, easy to install Java EE 6 server.
The test:

  1. Download size (apache-tomee-plus-1.0.0-beta-2.zip ): 43.8 MB (it is the biggest available download. It contains the Java EE 6 WebProfile with some "full profile" functionality)
  2. Installation = Unzip
  3. Disc size: 50.9 MB after installation
  4. Startup: same as tomcat: ./startup.sh
  5. Full deployment of ServerSmokeTest took < 2 secs.
  6. Tested were: Stereotypes (encapsulating @Named and @RequestScoped), @RequestScoped, @Named CDI-Beans, Injection of EJB 3.1 (no interface view), into CDI bean, @Singleton,@Stateless, CDI-events, POJO-injection, Interceptors
  7. ServerSmokeTest works without any modification on Glassfish v3, WebLogic 12c, JBoss 7.0.2, JBoss 6m5, SIwpas-1.0.0-CR4, resin-4.0.12 and even in the openshift cloud.

First impression: good. Easy to install, fast deployment, no problems. TomEE is another reason to get rid of the complicated and bloated Plain Old Web Containers :).
*NEW* Real World Java EE Night Hacks - Dissecting Best Practices ...and the bestseller Real World Java EE - Rethinking Best Practices

Java EE Bootstrap Workshop [Airport Munich]
Categories: Blogs

This Week in Grails (2012-04)

Peter Ledbrook started a HOWTO series this week for Grails; the first one is on upgrading to Grails 2.0 and there’s also a HOWTO on writing HOWTOs.

We could use your help finding invalid JIRA issues (e.g. already fixed or no longer an issue). Check out the section “Reviewing issues” in the wiki page on contributing to Grails for how to use the new “Last Reviewed” and “Flagged” fields.

Tomas Lin wrote up his experiences deploying Grails applications to AppFog. It’s great to know that there’s another viable cloud provider for Grails developers.

STS 2.9.0.M2 was released this week. Check out the new and noteworthy PDF for what’s been updated in the Groovy, Grails, and Gradle support.

I released a new plugin this week, to support using Ratpack in a Grails application. Thanks to James Williams for his post that got me started and inspired the plugin. And within a day there was already a blog post by Matthias Hryniszak on using the plugin.

If you want to keep up with these “This Week in Grails” posts you can access them directly via their category link or in an RSS reader with the feed for just these posts.

Translations of this post:

 Miscellaneous Items
 Plugins
 Interesting Tweets
 Jobs
 User groups and Conferences Miscellaneous Items Plugins

There were 3 new plugins released:

and 17 updated plugins:

  • atmosphere version 0.4.2.1. Provides integration with the Atmosphere project, a portable AjaxPush/Comet and WebSocket framework
  • ckeditor version 3.6.2.1. Implements the integration layer between Grails and the CKEditor web rich text editor.
  • date-formatting version 0.2.5. Adds functions to the Date object to convert into various string formats
  • foundation version 2.1.4.3. Provides the Foundation CSS framework resources
  • google-visualization version 0.5. Provides a taglib for the interactive charts of the Google Visualization API
  • grails-melody version 1.11. Integrates the JavaMelody system monitoring tool
  • gsp-taglib version 0.3.2. Makes it possible to declare tags in a gsp in grails-app/taglib
  • jasper version 1.5.2. Enables use of JasperReports
  • rich-domain version 1.0.6. Provides dependency injection for POGOs that are not Grails domain classes
  • spring-security-mock version 1.0.1. Mock authentication support for Spring Security
  • spring-security-saml version 1.0.0.M11. SAML 2.x support for the Spring Security Plugin
  • spring-security-shibboleth-native-sp version 1.0.2. Shibboleth Naitive SP support for the Spring Security grails plugin
  • syntax-highlighter version 3.0.83. Adds a Syntax Highlighter for displaying code samples in GSP pages
  • tiny-mce version 3.4.7. Integrates the TinyMce editor javascript and tags to embed the editor in your GSP pages
  • twitter4j version 0.3.2. Send and receive Twitter messages using the twitter4j library
  • xwiki-rendering version 0.4. Convert texts using XWiki Rendering Framework
  • zkui version 0.4.1. Seamlessly integrates ZK with Grails’ infrastructures; uses the Grails’ infrastructures such as GSP, controllers rather than zk’s zul as in ZKGrails plugin
Interesting Tweets Jobs User groups and Conferences

flattr this!

Categories: Blogs

Java Posse #377 - Newscast for Jan 26th 2012

The Java Posse - Tue, 01/31/2012 - 01:54
Newscast for January 26th 2012

Fully formatted shownotes can always be found at http://javaposse.com

Join us for the Java Posse Roundup in Crested Butte, CO. March 26th to 30th.
http://www.mindviewinc.com/Conferences/JavaPosseRoundup/

Quick News ScalaWags Android Clojure with a J Random Crap Thanks


The Java Posse consists of Tor Norbye, Carl Quinn, Joe Nuxoll and Dick Wall

Categories: Blogs

Legacy Refactoring

Java TV - Mon, 01/30/2012 - 23:51
This video shows the refactoring of Java legacy code and the presentation was given to the Java User Group Berlin Brandenburg. The beginning is a mess of ugly code that uses an HttpClient to acquire currency conversions. The higher-order goal of the code is to find deals in currency translation that result in a net positive. The talk discusses and explores: - Introducing an Instance Delegator - Making a resettable singleton - Using JMockit to work absolute black magic - Writing tests on top of existing legacy code - The woes of trying to get something ...
Categories: Blogs

I Hear Voices: JavaFX 2.1 Developer Preview for Linux

James Weaver’s JavaFX Blog - Mon, 01/30/2012 - 23:17
The release of the JavaFX 2.1 Developer Preview for Linux last week rounds out the Mac OS X and Windows releases that were already available. I thought that this would be an interesting time to take the pulse of the JavaFX community, so I asked several JavaFX developers to articulate the significance of this release. Here's what the 14 developers... Jim Weaver
Categories: Blogs

GlassFish / Jersey Exception "java.lang.IllegalArgumentException: object is not an instance of declaring class" And Solution

Adam Bien's Weblog - Mon, 01/30/2012 - 09:22
The exception:

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	[…]


is caused by exposing EJB 3.1 methods directly via REST without having a no-interface view declared. This happens when your EJB 3.1 REST-endpoint implements an additional interface without declaring the no-interface view:

import javax.ejb.*;

@Path("RESTafari)
@Singleton
public class RESTEndpoint implements SomeLocalInterface{}


Adding a @LocalBean annotation (and activating the no-interface view) solves the problem:


import javax.ejb.*;

@LocalBean
@Path("RESTafari)
@Singleton
public class RESTEndpoint implements SomeLocalInterface{}


*NEW* Real World Java EE Night Hacks - Dissecting Best Practices ...and the bestseller Real World Java EE - Rethinking Best Practices

Java EE Bootstrap Workshop [Airport Munich]
Categories: Blogs

Eclipse 4 Application Tutorial available (for Eclipse 4.2 M5)

Java and Eclipse News - Lars Vogel - Mon, 01/30/2012 - 07:10

A while ago I published an Eclipse e4 tutorial. Things have been moving quite a bit in Eclipse 4 since then.

I’m pretty excited about the capabilities of Eclipse 4, therefore I re-wrote my tutorial to show the capabilities of Eclipse 4.

This tutorial focuses on the application model and the dependency injection capabilities.

Eclipse 4 Tutorial.

More Eclipse 4 tutorials are available on http://www.vogella.de/eclipse.html in the category Eclipse 4 Development but I have not yet spend sufficient time to polish their content.

I hope you like it. It was a significant amount of work I invested into the description. Please let me know if you find errors.

I also would like to thank Brian de Alwis, Tom Schindl, Remy Suen, Paul Webster, John Arthorne and Eric Moffatt for answering my questions.

flattr this!

Categories: Blogs

Grails plugin for Ratpack

I saw James Williams’ post on Running Ratpack inside Grails earlier this week and thought that it should be implemented as a Grails plugin, so I started playing with it. There isn’t much in the way of documentation yet, but what’s there is at the plugin portal page. The source for the plugin is here if you have any fixes or suggestions.

flattr this!

Categories: Blogs

"Java Sucks" revisited

Vanilla Java - Thu, 01/26/2012 - 10:07
OverviewAn interesting document on Java's short comings (from C developer's perspective) was written some time ago (about 2000? ) but many of the arguments issues are as true (or not) today as they were ten years ago.

The original Java Sucks posting.

Review of short comingsJava doesn't have free().The author lists this as a benefit and 99% of the time is a win. There are times when not having it is a downside, when you wish escape analysiswould eliminate, recycle or free immediately an object you know isn't needed any more (IMHO the JIT / javac should be able to work it out in theory)

lexically scoped local functionsThe closest Java has is anonymous methods. This is a poor cousin to Closures (coming in Java 8), but it can be made to do the same thing.

No macro systemMany of the useful tricks you can do with macros, Java can do for you dynamically. Not needing a macro system is an asset because you don't need to know when Java will give you the same optimisations. There is an application start up cost that macros don't have and you can't do the really obfuscated stuff, but this is probably a good thing.

Explicitly Inlined functionsThe JIT can inline methods for you. Java can inline methods from shared libraries, even if they are updated dynamically. This does come at a run time cost, but its nicer not to need to worry about this IMHO.

I find lack of function pointers a huge painFunction pointers makes in lining methods more difficult for the compiler. If you are using object orientated programming, I don't believe you need these. For other situations, I believe Closures in Java 8 is likely to be nicer.

The fact that static methods aren't really class methods is pretty dumbI imagine most Java developers have come across this problem at some stage. IMHO: The nicest solution is to move the "static" functionality to its own class and not use static methods if you want polymorphism.

It's far from obvious how one hints that a method should be inlined, or otherwise go real fastMake it small and call it lots of times. ;)

Two identical byte[] arrays aren't equal and don't hash the sameI agree that its pretty ugly design choice not to make arrays proper objects. They inherit from Object, but don't have useful implementation for toString, equals, hashCode, compareTo. clone() and getClass() are the most useful methods. You can use helper methods instead, but with many different helper classes called Array, Arrays, ArrayUtil, ArrayUtils in different packages its all a mess for a new developer to deal with.

Hashtable/HashMap does allow you to provide a hashing functionThis is also a pain if you want to change the behaviour. IMHO, The best solution is to write a wrapper class which implements equals/hashCode, but this adds overhead.

iterate the characters in a String without implicitly involving half a dozen method calls per characterThere is now String.toCharArray() but this creates a copy you don't need and is not eliminated by escape analysis. When it is, this is the obvious solution.

The same applies to "The other alternative is to convert the String to a byte[] first, and iterate the bytes, at the cost of creating lots of random garbage"

overhead added by Unicode support in those cases where I'm sure that there are no non-ASCII characters. Java 6 has a solution to this which is -XX:+UseCompressedStrings. Unfortunately Java 7 has dropped support for this feature. I have no idea why as this option improves performance (as well as reducing memory usage) in test I have done.

Interfaces seem a huge, cheesy copout for avoiding multiple inheritance; they really seem like they were grafted on as an afterthought.I prefer a contract which only lists functionality offered without adding implementation. The newer Virtual Extension Methods in Java 8 will provide default implementations without state. In some cases this will be very useful.

There's something kind of screwy going on with type promotion The problem here is solved by co-variant return types which Java 5.0+ now supports.

You can't write a function which expects and Object and give it a shortToday you have auto-boxing. The author complains that Short and short are not the same thing. For efficiency purposes this can make surprisingly little difference in some cases with auto-boxing. In some cases it does make a big difference, and I don't foresee Java optimising this transparently in the near future. :|

it's a total pain that one can't iterate over the contents of an array without knowing intimate details about its contentsIts rare you really need to do this IMHO. You can use Array.getLength(array) and Array.get(array, n) to handle a generic array. Its ugly but you can do it. Its one of the helper class which should really be methods on the array itself IMHO.

The only way to handle overflow is to use BigInteger (and rewrite your code)Languages like Scala support operators for BigInteger and it has been suggested that Java should too. I believe overflow detection is also being considered for Java 8/9.

I miss typedefThis allows you to use primitives and still get type safety. IMHO, the real issue is that the JIT cannot detect that a type is just a wrapper for a primitive (or two) and eliminate the need for the wrapped class. This would provide the benefits of typedef without changing the syntax and make the code more Object Orientated.

I think the available idioms for simulating enum and :keywords are fairly lameJava 5.0+ has enum which are first class objects and are surprising powerful.

there's no efficient way to implement `assert'assert is now built in. To implement it yourself is made efficient by the JIT. (Probably not tens years ago)

By having `new' be the only possible interface to allocation, ... there are a whole class of ancient, well-known optimizations that one just cannot perform. This should be performed by the JIT IMHO. Unfortunately, it rarely does, but this is improving.

The finalization system is lame.Most people agree its best avoided. Perhaps it could be more powerful and reliable. ARM (Automatic Resource Management) may be the answer.

Relatedly, there are no ``weak pointers.''Java has always had weak, soft and phantom references, but I suspect this is not what is meant here. ??

You can't close over anything but final variables in an inner class!There is true of anonymous inner classes, but not nested inner classes referring to fields. Closures might not have this restriction but its likely to be just as confusing. Being used to the requirement for final variables, I don't find this problem esp. as my IDE will correct the code as required for me.

The access model with respect to the mutability (or read-only-ness) of objects blowsThe main complaint appears to be that there are ways of treating final fields as mutable. This is required for de-serialization and dependency injectors. As long as you realise that you have two possible behaviours, one lower level than the other, it is far more useful than it is a problem.

The language also should impose the contract that literal constants are immutable.Literal constants are immutable. It appears the author would like to expand what is considered a literal constant.

It would be useful IMHO, to support const in the way C++ does. const is a keyword in Java and the ability to define immutable versions of classes without creating multiple implementations or read only wrappers would be more productive.

The locking model is broken.The memory overhead of locking concern is really an implementation detail. Its up to the JVM to decide how large the header is and whether it can be locked. The other concern is that there is no control over who can obtain a lock. The common work around for this is to encapsulate your lock, which is what you would have to do in any case.

In theory the lock can be optimised away. Currently this only happens when the whole object is optimised way.

There is no way to signal without throwingFor this, I use a listener pattern with an onError method. There is no support in the language for this, but I don't see the need to.

Doing foo.x should be defined to be equivalent to foo.x(), Perhaps foo.x => foo.getX() would be a better choice, rather like C# does.

Compilers should be trivially able to inline zero-argument accessor methods to be inline object+offset loads.The JIT does this, rather than the compiler. This allows the calling code to be changed after the callee has been compiled.

The notion of methods "belonging" to classes is lame. This is a "cool" feature which some languages support. In a more dynamic environment, this can look nicer. The down side is that you can piece of code for a class all over the place and you would have to have some way of managing duplicates in different libraries. e.g. library A defines a new printString() method and library B also defines a printString method for the same class. You would need to make each library see its own copy and have some way of determining which version library C would want when it calls this method.

LibrariesIt comes with hash tables, but not qsortIt comes with an "optimised merge sort" which is designed to be faster.

String has length+24 bytes of overhead over byte[]That is without considering that each of the two objects are aligned to an 8 byte boundary (making it higher). If that sounds bad, consider that malloc can be 16-byte aligned with a minimum size of 32 bytes. If you use a shared_ptr to a byte[] (to give you similar resource management) it can be much larger in C++ than Java.The only reason for this overhead is so that String.substring() can return strings which share the same value array. This is not correct. The problem is that Java doesn't support variable sized objects (apart from arrays). This means that String object is a fixed size and to have variable sized field, you have to have another object. Its not great either way. ;)

String.substring can be a source of "memory leak"You have to know to take an explicit copy of you are going to retain a substring of a larger string. This is ugly, however the benefits usually out weight the down side. What would be a better solution is to be able to optimise the code so that a defensive copy was taken by default, except when the defensive copy is not needed (it is optimised away)

The file manipulation primitives are inadequateThe file system information has been improved in Java 7. I don't think these options are available, but can be easily inferred if you need to know this.

here is no robust way to ask ``am I running on Windows'' or ``am I running on Unix.'There are System properties os.name, os.arch, os.version which have always been there.

There is no way to access link() on Unix, which is the only reliable way to implement file locking. This was added in Java 7 Creating a Hard Link

There is no way to do ftruncate(), except by copying and renaming the whole file. You can use RandomAccessFile.truncate(). Adding in Java 1.4.

Is "%10s %03d" really too much to ask?It was added in Java 5.0

A RandomAccessFile cannot be used as a FileInputStream or FileOutputStreamRandomAccessFile supports DataInput and DataOutput, FileInputStream and FileOutputStream can be wrapped in DataInputStream and DataOutputStream. They can be made to support the same interfaces. I have never come across a situation where I would want to use both classes in a single method.

markSupported is stupidTrue. There are a number of stupid methods which are only there for historical purposes. Another being Object.wait(millis, nanos) on every object (even arrays) and yet the nanos is never really used.

What in the world is the difference between System and Runtime?I agree it appears arbitrary and in some cases doubled up. System.gc() actually calls Runtime.getRuntime().gc() and yet is called System GC even in internal code. In hind site they should really be one class with monitoring functionality moved to JMX.

What in the world is application-level crap like checkPrintJobAccess() doing in the base language class librarySo your SecurityManager can control whether you can perform printing. (Without having to have an Application level Security Manager as well) Not sure is this really prevents the need to have Application level security. ;)

Categories: Blogs