[英]How to use java ee 6 @Resource annotation
您的JDK(和我的)没有JSR-250的最新版本的javax.annotation.Resource
。 要在编译期间使用最新版本,您必须覆盖编译器的支持目录(例如,指向您的glassfishv3 endorsed目录):
-Djava.endorsed.dirs=${GLASSFISH_HOME}/modules/endorsed
在两种情况下都是相同的类( javax.annotation.Resource
)。 它只是为了方便而在两组API文档中。 实际的JavaEE 6实现将只使用JavaSE 6中的类。
线程坏死最好,但为了我的口味 - 尝试做干净整洁的事情 - javamonkey79的方法是太多的黑客。
这是我放在我的pom.xml中使其工作:
<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>
顺便说一句,我在这里找到了这个。 非常感谢,弗雷德里克!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.