Skip to main content

org.glassfish.main.javaee-api:javax.annotation:3.1.2 has wrong Resource annotation in it?

5 replies [Last post]
ljnelson
Offline
Joined: 2003-08-04
Points: 0

I hope this is pilot error.

I am depending on the following Maven artifact:

org.glassfish.main.ejb
javax.ejb
3.1.2
provided

This transitively brings in:

org.glassfish.main.javaee-api
javax.annotation
3.1.2
provided

So far so good.

I tried to use the javax.annotation.Resource annotation like this:

@Resource(lookup = "java:global/yadayada")
private DataSource ds;

...making use of the "lookup" attribute documented here:
http://docs.oracle.com/javaee/6/api/javax/annotation/Resource.html#lookup()

I received a compilation error:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/ljnelson/Projects/blah/Foo.java:[45,12] cannot find symbol
symbol : method lookup()
location: @interface javax.annotation.Resource
[INFO] 1 error

Baffled, I checked the class file with javap:

javap -classpath
/Users/ljnelson/.m2/repository/org/glassfish/main/javaee-api/javax.annotation/3.1.2/javax.annotation-3.1.2.jar
javax.annotation.Resource
Compiled from "Resource.java"
public interface javax.annotation.Resource extends
java.lang.annotation.Annotation{
public abstract java.lang.String name();
public abstract java.lang.Class type();
public abstract javax.annotation.Resource$AuthenticationType
authenticationType();
public abstract boolean shareable();
public abstract java.lang.String mappedName();
public abstract java.lang.String description();
}

There is no lookup() attribute in there. Should there be?

Best,
Laird

--
http://about.me/lairdnelson

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shalini Guest
Offline
Joined: 2011-04-18
Points: 0

Hi Laird,

Could you try adding the following in your pom.xml?

maven-compiler-plugin

-Djava.endorsed.dirs="${gf.home}/modules/endorsed"

This is to instruct maven to endorse dependencies during compile.

Thanks
Shalini.

On Saturday 04 August 2012 01:57 AM, Laird Nelson wrote:
> I hope this is pilot error.
>
> I am depending on the following Maven artifact:
>
>
> org.glassfish.main.ejb
> javax.ejb
> 3.1.2
> provided
>
>
> This transitively brings in:
>
>
> org.glassfish.main.javaee-api
> javax.annotation
> 3.1.2
> provided
>
>
> So far so good.
>
> I tried to use the javax.annotation.Resource annotation like this:
>
> @Resource(lookup = "java:global/yadayada")
> private DataSource ds;
>
> ...making use of the "lookup" attribute documented here:
> http://docs.oracle.com/javaee/6/api/javax/annotation/Resource.html#lookup()
>
>
> I received a compilation error:
>
> [ERROR] COMPILATION ERROR :
> [INFO] -------------------------------------------------------------
> [ERROR] /Users/ljnelson/Projects/blah/Foo.java:[45,12] cannot find symbol
> symbol : method lookup()
> location: @interface javax.annotation.Resource
> [INFO] 1 error
>
> Baffled, I checked the class file with javap:
>
> javap -classpath
> /Users/ljnelson/.m2/repository/org/glassfish/main/javaee-api/javax.annotation/3.1.2/javax.annotation-3.1.2.jar
> javax.annotation.Resource
> Compiled from "Resource.java"
> public interface javax.annotation.Resource extends
> java.lang.annotation.Annotation{
> public abstract java.lang.String name();
> public abstract java.lang.Class type();
> public abstract javax.annotation.Resource$AuthenticationType
> authenticationType();
> public abstract boolean shareable();
> public abstract java.lang.String mappedName();
> public abstract java.lang.String description();
> }
>
> There is no lookup() attribute in there. Should there be?
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>

atomicknight
Offline
Joined: 2010-03-14
Points: 0

The JAR actually does have the lookup attribute - the problem is that your command is picking up the 1.0 version of @Resource from the JDK instead of the 1.1 version from the JAR. If you use the following command, you should see it:

javap -bootclasspath /Users/ljnelson/.m2/repository/org/glassfish/main/javaee-api/javax.annotation/3.1.2/javax.annotation-3.1.2.jar
javax.annotation.Resource

You can also check this by opening Resource.class from the JAR in a text file.

This is also the root of the original problem: the compiler is picking up the JDK version, which has precedence over external libraries by default. You'll need to pass the "-endorseddirs" flag to javac.

ljnelson
Offline
Joined: 2003-08-04
Points: 0

Thank you! It had not occurred to me that javax.annotation.Resource was in the JDK but of course it is.

I guess I will have to come up with some Maven recipe for including that area of the local Maven repository as an endorsed directory, but only when this particular dependency is in play.

Thanks again.

Best,
Laird

atomicknight
Offline
Joined: 2010-03-14
Points: 0

One possibility is to use the maven-dependency-plugin to copy the JAR to your output directory and then reference it via a Maven property that could then be passed to the maven-compiler-plugin.

ljnelson
Offline
Joined: 2003-08-04
Points: 0

[quote=atomicknight]One possibility is to use the maven-dependency-plugin to copy the JAR to your output directory and then reference it via a Maven property that could then be passed to the maven-compiler-plugin.[/quote]

Yep; basically what I'm setting up right now. :-)

Best,
Laird