5 Replies Latest reply: Jan 24, 2010 4:28 AM by 794081 RSS

    How to process my own custom annotation

    843793
      I am developing an application where I am using JDBC for database connectivity. So here I want to develop a custom annotation to provide the connection parameters and database urls etc. (Just for learning the annotations). But I am unsure that how can I process the annotation just like hibernate and other APIs do?

      Can anyone help me? I am using JDK 5.

      Thanks in advance.

      VP
        • 1. Re: How to process my own custom annotation
          jtahlborn
          for creating your own annotation, see any one of the many tutorials out there, google is great for this. for accessing them at runtime, see the javadoc for java.lang.reflect.AnnotatedElement.

          Edited by: jtahlborn on Dec 22, 2009 3:35 PM
          • 2. Re: How to process my own custom annotation
            843793
            Hi jtahlborn,

            Actually I created one custom annotation as I saw an example of command line processing annotation. I created annotation processor also. But the problem is
            -process option is not available in javac. is that only available in JDK 6? What is the alternative solution to process the annotation in JDK 5?

            Thanks

            VP
            • 3. Re: How to process my own custom annotation
              843793
              vishnuprakash wrote:
              Hi jtahlborn,

              Actually I created one custom annotation as I saw an example of command line processing annotation. I created annotation processor also. But the problem is
              -process option is not available in javac. is that only available in JDK 6? What is the alternative solution to process the annotation in JDK 5?
              For JDK 5, you can use the first-generation "apt" (annotation processing tool) command line program included in the JDK bin directory. The annotation processing support in javac in JDK 6 is the second-generation much improved and standardized version of the apt API and functionality.

              However, especially since JDK 5 is end-of-support-life, I strongly suggest you to try to use javac in JDK 6 instead.
              • 4. Re: How to process my own custom annotation
                jtahlborn
                j.d.darcy wrote:
                For JDK 5, you can use the first-generation "apt" (annotation processing tool) command line program included in the JDK bin directory. The annotation processing support in javac in JDK 6 is the second-generation much improved and standardized version of the apt API and functionality.
                fyi, the apt tool is for doing annotation processing at compile time.
                • 5. Re: How to process my own custom annotation
                  794081
                  I recently came across this [Google Reflection Library|http://code.google.com/p/reflections/] and I really find it useful not only if you have to process/evaluate annotations at runtime, but also for reflection stuff in general. Have a look at it, usage is pretty straight-forward.