Community
Participate
Working Groups
Hi, I wrote a custom annotation and have used my custom annotation in my java class. I was able to compile the same sucessfully with jdk1.5.0_06. I wrote an aspect with annotations and when tried to compile the same iam getting errors. Pls find attached my sample code and the error which i am getting. My Custom Annotation ******************** import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation{ } My Java Class using my Custom Annotation **************************************** public class AnnotationTestClass{ static AnnotationTestClass objTest; public static void main(String[] args) { objTest = new AnnotationTestClass(); objTest.methodA(); } @MyAnnotation public void methodA(){ System.out.println("This is methodA"); objTest.methodB(); } @MyAnnotation public void methodB(){ System.out.println("This is methodB"); } } My Aspect to cut the annotated methods ************************************** public aspect AnnotationTestAspect{ pointcut annotatePointcut() : call(@MyAnnotation * *(..)); before() : annotatePointcut(){ System.out.println("Joinpoint : " + thisJoinPoint); } } I have an execute.lst file as below, AnnotationTestAspect.java AnnotationTestClass.java MyAnnotation.java When compiled as follows, i get the following errors, D:\Study\AspectJ\13-01-06>ajc @executeList.lst D:\Study\AspectJ\13-01-06\AnnotationTestAspect.java:3 [error] annotation type patterns are only supported at Java 5 compliance level or above pointcut annotatePointcut() : call(@MyAnnotation * *(..)); ^^^^^^^^^^ D:\Study\AspectJ\13-01-06\AnnotationTestClass.java:10 [error] Syntax error, annotations are only available if source level is 5.0 @MyAnnotation ^^^^^^^^^^^ D:\Study\AspectJ\13-01-06\AnnotationTestClass.java:16 [error] Syntax error, annotations are only available if source level is 5.0 @MyAnnotation ^^^^^^^^^^^ D:\Study\AspectJ\13-01-06\MyAnnotation.java:3 [error] Syntax error, annotations are only available if source level is 5.0 @Retention(RetentionPolicy.SOURCE) ^^^^^^^^^ D:\Study\AspectJ\13-01-06\MyAnnotation.java:4 [error] Syntax error, annotation declarations are only available if source level is 5.0 public @interface MyAnnotation{ ^^^^^^^^^^^ In ajc.bat the java home is set to the home of jdk1.5.0_06. Please let me what is the problem. Regards R.S.Dhanalakshmi
Unlike javac, ajc does not default to 1.5 compliance level. You need to compile with the -1.5 flag: ajc -1.5 @executeList.lst
I presume switching on the -1.5 flag fixed this... if not then feel free to reopen.