April 9, 2020
Estimated Post Reading Time ~

Issues while Migrating from Java6 to Java8 in AEM 6.1

Recently while working on AEM 6.1, I had to move from Java 6 to Java 8. Simply changing the Java version in POM led to some issues with OSGi services. Specifically, those services that were using @Reference annotation were not getting active and remained in the “satistied” state.

Here are all the steps I followed firstly to change Java version and then fixing the above-mentioned issue:
1. To build an AEM project with Java8 as a runtime environment, the following configuration is required in pom.xml. The Compiler Plugin is added to the parent POM, it is used to compile the sources of your project.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

The default source and target setting is 1.5. If you want to change it to work with Java 8, you should set the source and target to 1.8.
2. If you want to use scr annotations in your project, you have to use a maven-scr-plugin. And its version >= 1.17.0 for Java8

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.17.0</version>
</plugin>

3. For SCR annotations, following dependency should be added in the project with the version >= 1.9.8 for Java8

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.9.8</version>




By aem4beginner

No comments:

Post a Comment

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