3

I'm just new to annotations. I've created a sample annotationProcessor to handle my annotations and currently using command line script "-processor defaultproject.annotations.DefaultProcessor " to use it.

is there any way to set this processor from inside the code?

thanks a lot Moein

1 Answer 1

1

The Processor interface says this about the discovery process:

The tool uses a discovery process to find annotation processors and decide whether or not they should be run. By configuring the tool, the set of potential processors can be controlled. For example, for a JavaCompiler the list of candidate processors to run can be set directly or controlled by a search path used for a service-style lookup. Other tool implementations may have different configuration mechanisms, such as command line options; for details, refer to the particular tool's documentation.

Your best bet for defining the processor in your classpath is to provide a META-INF/services/javax.annotation.processing.Processor file containing the text defaultproject.annotations.DefaultProcessor.

(Assuming your tool chain supports this mechanism. This is ultimately compiler/tool/IDE dependent.)

Sign up to request clarification or add additional context in comments.

2 Comments

So sorry I did try , like this : <code> ArrayList<Processor> processors processors.add(new MyDefaultProcessor()); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); CompilationTask compilationTask = compiler.getTask(null, fileManager, null, null, null, null); compilationTask.setProcessors(processors); compilationTask.call(); </code> But I don't know how to replace parameters currently passed 'null'. Thanks a lot
@user847577 - see this developerWorks article by David Biesack on dynamic compilation. If you are still having trouble invoking the API, that should probably be a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.