How to use java ee 6 @Resource annotation

In java ee 6 api, there is an @Resource annotation with the 'lookup' attribute, however it is also java se 6 api ( here ). However, since java ee 6 is dependent on java se 6, it seems you cannot get the ee version of the annotation and lookup attribute.

Is this a mistake or is there some other way to use this annotation that I am missing.

TIA

+4
source share
3 answers

Your JDK (and mine) does not have the latest javax.annotation.Resource from JSR-250 . To use the latest version at compile time, you will have to redefine the directory approved by the compiler (for example, specify your directory approved by Glassfishv3):

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

This is the same class in both cases ( javax.annotation.Resource ). This is in both sets of API documents for convenience. Actual implementations of JavaEE 6 will use this class only with JavaSE 6.

+2
source

A thread is necro at best, but to my taste - trying to do something clean and tidy - the javamonkey79 approach is too much of a problem.

Here is what I put into 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 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 it here . Thanks so much Frederick!

+2
source

Source: https://habr.com/ru/post/1304804/


All Articles