Sonntag, 30. Januar 2011

@Resource annotation and lookup

The problem...
In the last hours I unfortunately had to fight a bit with the @Resource annotation in combination with the parameter "lookup". Many examples out there mention this new added parameter in JavaEE6. And i wanted to try. So an example webapp I downloaded worked fine. But as soon as I tried to use it in my project, i kept getting a "cannot find symbol" error message. I examined further and found out that the resource annotation can be found in the latest JDK 1.6, but also inside my maven dependency "javaee-api-6.0.jar". Unfortunately NetBeans always took the wrong version.

The solution...
is quite simple, if you use maven. I switched from Eclipse to Maven some weeks ago and used it´s wizzard to create my EJB modules. The netbeans modules unfortunately handle the pom.xml a bit different than the default archetypes. If you try to create a standard maven ejb module, the following xml is being created and even documented. This one will help you out:

<!-- javaee6 contains upgrades of APIs contained within the JDK itself.
As such these need to be placed on the bootclasspath, rather than classpath of the
If you don't make use of these new updated API, you can delete the profile.
On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->


  1. Thank you, Frederik!
    This solution worked for me.

  2. Thanks, I spent hours going round in circles on this


Hier kann jeder (auch unregistrierte) Leser seine Meinung kundtun...