Forum Stats

  • 3,757,778 Users
  • 2,251,265 Discussions


Common annotation 1.1 on Javaee6

843830 Member Posts: 47,913 Green Ribbon
edited Aug 10, 2011 12:33PM in Java Message Service (JMS)
import javax.annotation.Resource;
I try to use the following code for dependecy injection:

@Resource(lookup = "jms/javaee6/ConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/javaee6/Queue")
private static Queue queue;

However, when I build with maven. The error message keeps showing
cannot find symbol
symbol : method lookup()
location: @interface javax.annotation.Resource

Anything i can do in order to make it works?



  • 805009
    805009 Member Posts: 122
    That's because "lookup" isn't a valid method on javax.annotation.Resource. Try "name".

  • 843830
    843830 Member Posts: 47,913 Green Ribbon
  • shelleyb
    shelleyb Member Posts: 9
    javax.annotation.Resource does include a "lookup" method as of Java EE 6.
  • shelleyb
    shelleyb Member Posts: 9
    The problem with building this in Maven is that the JDK also includes a javax.annotation.Resource which does not yet include the "lookup" method -

    In order to get it to build with Maven, you will need to add the JAR containing the correct javax.annotation.Resource to an endorsed JAR. This can be done by using the maven-dependency-plugin to copy the JAR to a directory, and then configuring the compiler plugin to reference the endorsed dir: -Djava.endorsed.dirs=${}/endorsed.

    The following blog post includes more detailed information -
  • Nigel Deakin-Oracle
    Nigel Deakin-Oracle Member Posts: 115
    edited Aug 10, 2011 12:33PM
    You're quite right, of course. @Resource(lookup="foo") is perfectly valid in Java EE 6, with several examples in the spec. Thanks for explaining why it doesn't always compile, even with Java EE 6 in the classpath.

This discussion has been closed.