Annotation Processor in Eclipse [Solved]
-
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
-
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
Do you have an
AnnotationProcessorFactory
? This is required to interface to the actualAnnotationProcessor
.
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
-
Do you have an
AnnotationProcessorFactory
? This is required to interface to the actualAnnotationProcessor
.
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
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
-
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
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
-
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
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.MyAnnotationProcessor2Then, 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