开发者

How to use java ee 6 @Resource annotation

The java ee 6 api has an annotation @Resource with an attribute 'lookup', however, so does the java se 6 api (here). However, since java ee 6 is dependent on java se 6, it seems you can not get at the ee version of the annotation and the 'lookup' attribute.

Is this a bug or is开发者_如何学Go there some other way to use this annotation that I am missing.

TIA


Your JDK (and mine) doesn't have the latest version of the javax.annotation.Resource from the JSR-250. To use the latest version during compilation, you'll have to override the compiler's endorsed directory (e.g. to point to your glassfishv3 endorsed directory):

-Djava.endorsed.dirs=${GLASSFISH_HOME}/modules/endorsed


It's the same class in both cases (javax.annotation.Resource). It's in both sets of API docs for convenience only. Actual JavaEE 6 implementations will just use the class from JavaSE 6.


Thread necro at its best, but for my taste - trying to do things clean and neat - the approach of javamonkey79 is just too much of a hack.

This is what I put in my pom.xml to make it work:

<profiles>
        <profile>
            <id>endorsed</id>
            <activation>
                <property>
                    <name>sun.boot.class.path</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <!-- 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
                                 compiler.
                                 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.-->
                            <compilerArguments>
                                <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
                            </compilerArguments>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

By the way, I found this here. Thanks a lot, Frederik!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜