Monday, August 4, 2014

Override annotation compilation problem - Liferay 6.1 Plugins SDK

You have classes implementing interface methods, which in Java 1.6 can be annotated with @Override; however, in Java 1.5, @override could only be applied to methods overriding a superclass method.

So while using liferay 6.1 plugins SDK, if you use @override annotations for implementing interface methods, though the server JDK is at 1.6, it still complains, resulting in not compiling the class with that annotation. Here is the example:

When creating a model listener hook, you need to implement all of the methods present in the ModelListener interface. If the implemented class has annotation "override", while building using the ant, it gives compilation error. 

Temporary fix

Remove @override annotation and build the project using ant.

Permanent Fix

To solve this issue the compiler compliance level should be set to 1.6. As we are building from ant, we have to set the compiler compliance level of ant. This can be set in build.properties file present in the plugins SDK root directory. All you need to do is change the following properties to 1.6

ant.build.javac.source=1.6

ant.build.javac.target=1.6

No comments:

Post a Comment