10 Replies Latest reply on Jul 21, 2005 11:42 PM by natebowler

    annotationc on jdk 1.4.2

    natebowler Newbie

      I would like to use annotations to define my method pointcuts.

      Specifically, I have gone through my source code and have added:


      annotation to all methods I want to have intercepted. This includes a SPACE at the end (not sure if this is required by qdox or not when no attributes are defined).

      My jboss-aop.xml looks like this (without brackets):

      interceptor name="optimisticlockretry" class="biz.OptimisticLockRetryInterceptor"/

      pointcut name="optimisticLockRetryMethods" expr="execution(public static * biz.*->@OptimisticLockRetry(..))"/

      bind pointcut="optimisticLockRetryMethods"
      interceptor-ref name="optimisticlockretry"/

      My understanding is, that in my Ant build file I should compile all my class files, then run annotationC, then run AOPC.

      My build is failing on the annotationC step. I should note that before introducing Annotations, my JBoss AOP setup worked fine.

      I have defined an empty interface named "biz.OptimisticLockRetry" (again, not sure if this is required or not. I've tried with and without).

      The Ant task to run AnnotationC is as follows:

      annotationc compilerclasspathref="aop.classpath.path.id" classpath="${classes.dest.dir}" bytecode="true"
      src path="${src.dir}"/

      However, I get parsing error complaining about tokens that are not in my source files. My thinking is that annotationC is picking up my CVS files. I've tried several ways of changing up the tag, and can get it to run, but nothing changes on my files.

      So, my questions are:

      1- Is my understanding correct in how Annotations can be used to define my pointcuts?
      2- How can I define my annotationc Ant Task to execute this tool correctly. I would like to precompile my classes the same I way I was before, but by using Annotations rather than naming expressions.

        • 1. Re: annotationc on jdk 1.4.2
          Bill Burke Master

          make sure your references to the annotation are fully qualified in your pointcut expressions. annotations are interfaces.

          • 2. Re: annotationc on jdk 1.4.2
            natebowler Newbie

            OK, I've added the package. But still nothing. How can I verify if the Annotations are being added?

            The only way I can get the Ant Task to run without a parse error is by changing the src tag to.

            fileset dir="${src.dir}"
            include name="*.java"/

            in order to filter out other files.

            I assume my error is either:

            1- the Annotations are not being marked correctly.
            2- Or they are, and my jboss-aop.xml isn't defined correctly to pick them up.

            I'm leaning towards #1 being the problem, but can I verify this? If I do an XML output, I get an empty metadata-aop.xml file (well, tags with nothing in them).

            • 3. Re: annotationc on jdk 1.4.2
              Bill Burke Master

              I should probably create an annotationc task to show annotations.

              but, here's how you can do it:

              put javassist.jar, jboss-aop.jar, trove,.jar, etc... into your classpath
              add your classes to the classpath as well.


              java org.jboss.aop.annotation.util.FindAnnotations fully.qualified.class.name

              where fully.qualified... is the classname

              It will print out a bunch of stuff and show you where annotations lie.


              • 4. Re: annotationc on jdk 1.4.2
                Bill Burke Master

                P.S. Apoloogies for all your troubles.

                • 5. Re: annotationc on jdk 1.4.2
                  natebowler Newbie


                  Sorry to take so long in my response, but this was put on hold and I am just now getting back into it. I have followed your instructions and yes, I can pring out A LOT of information. I'm not sure what this is, but I can't see any information regarding Annotations.

                  Just to sum up again, I am using JDK 1.4.2, and I am trying to annotate my code. The annotationc tag in my Ant file is as follows and runs successfully:

                  [annotationc compilerclasspathref="redrock.aop.classpath.path.id" classpath="${ejb.dest.dir}" xml="true"]
                  [src ]
                  [fileset dir="${src.dir}"]
                  [include name="*.java"/]

                  I have an interface named "biz.OptimisticLockRetry". The method I want to have intercepted is annotated using:

                  * @@biz.OptimisticLockRetry

                  My pointcut in jboss-aop.xml is defined using:

                  [pointcut name="optimisticLockRetryMethods" expr="execution(public static * *->@biz.OptimisticLockRetry(..))"/]

                  Is there something obvious I'm missing here?

                  • 7. Re: annotationc on jdk 1.4.2
                    natebowler Newbie

                    I'm running out of ideas here, there has got to be something I'm missing but as I keep going through the checklist I'm not catching it. I have changed my ant file to:

                    [taskdef name="annotationc" classname="org.jboss.aop.ant.AnnotationC" classpath="${aop.classpath}"/]
                    [annotationc compilerclasspathref="redrock.aop.classpath.path.id" classpath="${ejb.dest.dir}" bytecode="true"]
                    [fileset dir="${src.dir}"]
                    [include name="*.java"/]

                    But, I still get no encodings. Everything else is the same as my previous post. The Ant output is:

                    "[annotationc] Working directory ignored when same JVM is used."

                    Also, I am concerned that when I added the "verbose="true"" attribute to the annotationc tag, I got an error saying "verbose was not supported".

                    I am using JBoss AOP 1.3 with JDK 1.4.2 on Windows XP.

                    If it helps, the Java interface is defined as:

                    package biz;
                    public interface OptimisticLockRetry {}

                    As a side note, when I had the "xml="true"" attribute set, my resultant XML file was empty . It's just not picking up these annotations.

                    The "verbose not supported" concerns me though. Should I start looking at classpath/library issues?


                    • 8. Re: annotationc on jdk 1.4.2
                      Bill Burke Master

                      You must have your classes compiled before you run annotationc. These classes must be available in your classpath. These classes cannot be in a JAR, they must be in a directory classpath.

                      • 9. Re: annotationc on jdk 1.4.2
                        natebowler Newbie

                        Yes I got that. If it helps, this is my javac call:

                        [javac debug="on"
                        [src path="${src.dir}"/]
                        [src path="${gensrc.dir}"/]

                        The target this tag is in is called prior to the target running [annotationc].

                        ${ejb.dest.dir} is a directory.It *is* named using the ".jar" suffix per JBoss deployment specifications, I' m not sure if that makes any difference.

                        Is the fact that the [annotationc] tag is giving an error on "verbose" a cause of concern (as in I've got a bad version or an old verison)? Also, if I don't use a [fileset] inside my [src] tag I get a parse error, which I'm not sure if CVS files are causing it to choke or what.

                        Again, I'm just trying to mention as much as possible to see if anything comes across as significant.

                        • 10. Re: annotationc on jdk 1.4.2
                          natebowler Newbie

                          Ok, I got it working.

                          The way I used the [annotationc] with a [fileset] did not work. My files were not being examined. When I changed it to use an [include] tag with the [src] tag, it started to examine the files.

                          Once this worked, I discovered I had several methods marked that had comments AFTER the markup @@biz.OptimisticLockRetry. I guess you CAN'T have anything after this or you get a parse error. :)

                          This is fairly obvious, I suppose, but it was easy to fix once I started getting messages.

                          At any rate, thanks for the help. It's working great.