我需要使用JDK 11编译一些代码,它使用 javax.annotation 包的Java EE版本 . 具体来说,我想使用 @Resource 作为可重复的注释(Common Annotations 1.3 spec),而注释在JDK 8中是不可重复的 . 另外,我需要在Java 8字节码级别编译此代码,因为我的代码仍然需要运行JDK 8 .

如果我用 javac --release 8 编译我的代码,那么我被迫使用 javax.annotations 的JDK 8版本 . 理想情况下,我想使用--upgrade-module-path,但 javac 阻止此选项:

javac --release 8 --upgrade-module-path /path/to/upgraded/module/
error: option --upgrade-module-path cannot be used together with --release

在之前的Java级别中,我会将我的 javax.annotion jar添加到bootclasspath,但是这也被 --release 阻止了

$ javac --release 8 --boot-class-path foo
error: option --boot-class-path cannot be used together with --release

有没有办法安全地编译到较旧的java级别,同时还覆盖/升级特定的包/模块?