January 2, 2021
Estimated Post Reading Time ~

The Java Commons Annotations Was Removed in JDK 11

The Java Common Annotations Module java.xml.ws.annotation was deprecated in Java version 9 and was removed in java version 11. So what does this mean for your AEM 6.5 project running on JDK 11?

AEM 6.5 and JDK 11
As of AEM 6.5, JDK 11 is supported alongside JDK 8. As such, Devs will begin developing and testing AEM on JDK 11 you can check the technical requirements and see Adobe’s notes on JDK 11. You should also read the Oracle/Adobe License Agreement. also read Dan’s post on the matter here.

The Java Common Annotations Module
As an AEM dev, you probably did not realize it, but you were using this module all along. The @PostConstruct annotation used by sling models is part of that module. The removal of that module from JDK 11 means that you’ll get a compile error on any classes that use that annotation.

Including the Java Common Annotations Dependency in Your Project
The solution to this problem, as it turns out, is pretty simple: Include the dependency yourself in your maven project.

see: [1] and [2]
<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
    <scope>provided</scope>
</dependency>


You might be wondering, what about the OSGi container? Doesn’t it run on the same JDK? well, yes! but it uses a different dependency! go to http://localhost:4502/system/console/depfinder and look for javax.annotations.*

and you’ll see it uses this dependency:
<dependency>
    <artifactId>geronimo-annotation_1.3_spec</artifactId>
    <version>1.0</version>
    <groupId>org.apache.geronimo.specs</groupId>
    <scope>provided</scope>
</dependency>

You can use whichever dependency works for you, so long as you have it in your project!


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.