I am writing an annotation processor in Java and in this annotation processor I want to be able to find a file in the Project hierarchy of the project on which I am using this annotation processor. Through the annotation I can pass in the path of the file I am searching for relative to the project root but i cannot retrieve the project's working directory.
Let's say that the processor is MyCustomProcessor and I am using it on the project MyProject. I want to be able to access(read) a file (a properties file) from the project structure of MyProject from the "process" method of MyCustomProcessor.
I have read this link Eclipse - Annotation processor, get project path but when I use their solution I get a null returned from the StandardJavaFileManager.getLocation(StandardLocation.SOURCE_PATH)
call.
Some more details regarding the implementation:
MyAnnotationProcessor:
@SupportedAnnotationTypes(value = {"MyAnnotation" })
@SupportedSourceVersion(RELEASE_6)
public class MyCustomProcessor extends AbstractProcessor {
...
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
for (final Element element : roundEnv.getElementsAnnotatedWith(MyAnnotation.class)) {
<!-- Here is where I would like to get the working directory !-->
}
}
}
More details about the testing and development environment: Eclipse Kepler, JRE 1.7.
If you need more details just ask.