Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Annotation Processor in Eclipse [Solved]

Annotation Processor in Eclipse [Solved]

Scheduled Pinned Locked Moved Java
helptutorialjavadockerdata-structures
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skippums
    wrote on last edited by
    #1

    Does anyone know how to get an annotation processor to work in Eclipse? These are the steps that I have taken thus far: 1) Export the annotation and associated processor into a JAR file 2) Open Project->Properties, and select "Java Compiler"->"Annotation Processing"->"Factory Path" from the tree view on the left, and click "Add External JARs...". After completing these steps, when I select my JAR file and click the Advanced button, I get a dialog that has an empty listbox labeled "Processors in this container". Why is Eclipse not seeing my annotation processor? I have included some simple code to illustrate the problem:

    // Test.java
    package NAMESPACE;

    public @interface Test {}

    // TestProcessor.java
    package NAMESPACE;

    import java.util.Set;

    import javax.annotation.processing.*;
    import javax.lang.model.element.TypeElement;

    @SupportedAnnotationTypes({"NAMESPACE.Test"})
    public class TestProcessor extends AbstractProcessor {
    @Override
    public boolean process(
    Set annotations,
    RoundEnvironment roundEnv) {
    return true;
    }
    }

    This example is about as simple as I can make it. Please help me to figure out why this isn't being found by Eclipse's annotation processor. Thanks,

    Sounds like somebody's got a case of the Mondays -Jeff

    N 1 Reply Last reply
    0
    • S Skippums

      Does anyone know how to get an annotation processor to work in Eclipse? These are the steps that I have taken thus far: 1) Export the annotation and associated processor into a JAR file 2) Open Project->Properties, and select "Java Compiler"->"Annotation Processing"->"Factory Path" from the tree view on the left, and click "Add External JARs...". After completing these steps, when I select my JAR file and click the Advanced button, I get a dialog that has an empty listbox labeled "Processors in this container". Why is Eclipse not seeing my annotation processor? I have included some simple code to illustrate the problem:

      // Test.java
      package NAMESPACE;

      public @interface Test {}

      // TestProcessor.java
      package NAMESPACE;

      import java.util.Set;

      import javax.annotation.processing.*;
      import javax.lang.model.element.TypeElement;

      @SupportedAnnotationTypes({"NAMESPACE.Test"})
      public class TestProcessor extends AbstractProcessor {
      @Override
      public boolean process(
      Set annotations,
      RoundEnvironment roundEnv) {
      return true;
      }
      }

      This example is about as simple as I can make it. Please help me to figure out why this isn't being found by Eclipse's annotation processor. Thanks,

      Sounds like somebody's got a case of the Mondays -Jeff

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Do you have an AnnotationProcessorFactory? This is required to interface to the actual AnnotationProcessor.


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      S 1 Reply Last reply
      0
      • N Nagy Vilmos

        Do you have an AnnotationProcessorFactory? This is required to interface to the actual AnnotationProcessor.


        Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

        S Offline
        S Offline
        Skippums
        wrote on last edited by
        #3

        I did see something about that class in my online searching, but it looked as though that only applied if you are using the Java 1.5 mirror API, which I think is deprecated in 1.7. Is my understanding about this correct? If not, it seems weired to be using something from the "com.sun.mirror.apt" namespace with other classes from the "javax.annotation.processing" namespace. Thanks for the help,

        Sounds like somebody's got a case of the Mondays -Jeff

        N 1 Reply Last reply
        0
        • S Skippums

          I did see something about that class in my online searching, but it looked as though that only applied if you are using the Java 1.5 mirror API, which I think is deprecated in 1.7. Is my understanding about this correct? If not, it seems weired to be using something from the "com.sun.mirror.apt" namespace with other classes from the "javax.annotation.processing" namespace. Thanks for the help,

          Sounds like somebody's got a case of the Mondays -Jeff

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #4

          TBH, I just had a quick browse and everything I could find referenced it. It may well be worth you re-reading the API docs.


          Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

          S 1 Reply Last reply
          0
          • N Nagy Vilmos

            TBH, I just had a quick browse and everything I could find referenced it. It may well be worth you re-reading the API docs.


            Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

            S Offline
            S Offline
            Skippums
            wrote on last edited by
            #5

            Ah! I figured it out... the following link showed a subtle step that I missed the first time through: Annotation Processing in Eclipse[^] Apparently, I needed to include the file "META-INF\services\javax.annotation.processing.Processor" in my project directory. This file contains the fully-qualified class name of each implementation of the Processor class, one per line, as follows:

            NAMESPACE1.MyAnnotationProcessor1
            NAMESPACE2.MyAnnotationProcessor2

            Then, I had to select the "Run this container's processors in batch mode" checkbox in the "Advanced" options for my JAR in the "Annotation Processing"->"Factory Path" settings. Thanks for the help

            Sounds like somebody's got a case of the Mondays -Jeff

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups