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 “satistied” state.
Here are all the steps I followed firstly to change Java version and then fixing above mentioned issue:
1. To build an AEM project with Java8 as runtime environment, 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.
[java]
<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>
[/java]
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 maven-scr-plugin. And its version >= 1.17.0 for Java8
[java]
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.17.0</version>
</plugin>
[/java]
3. For SCR annotations, following dependency should be added in the project with the version >= 1.9.8 for Java8
[java]
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.9.8</version>
</dependency>
[/java]
Let me know if you face any issue with this by commenting on this post.
Hope this helps!!!
Good to know