Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run JSR269 annotaion processor in Eclipse Kepler with Java 7 & Maven

I'm using eclipse Kepler and the compiler is set to use Java 7. I have a JSR269 compliant annotation processor in my classpath (in the maven container).

What is the easiest way to run this annotation processor?

Actually I would expect the Eclipse compilation to run this annotation processor automatically during the build since it is JSR 269 compliant - but it doesn't. Why not-is it for performance reasons?

Note: the maven build from the command line works just fine.

After some research it turned out that this can be configured in the Project properties (Java Compiler - Annotation processing - Factory Path). The question here is that I do of course want to use the annotation processor's .jar file that is already on the classpath (in the Maven Container). How can I refer to it? I found no way to do it.

The best I came up with is to use the M2_REPO variable and then manually append the path to the processor like so:

M2_REPO/com/gwtplatform/gwtp-processors/1.0.1/gwtp-processors-1.0.1.jar

this obviously has the problem that the processor is now specified on 2 places: in the maven pom file and in the eclipse project. How to avoid this?

like image 636
TmTron Avatar asked Oct 02 '22 17:10

TmTron


1 Answers

You need an m2e connector which automatically configures your Eclipse project for the annotation processing.

The m2e connector to use depends on how you have configured the annotation processing on the Maven side. If you just rely on the maven-compiler-plugin to find your annotation processor, or if you have configured the maven-annotation-plugin for that, then you can use the connector m2e-apt by JBoss.

m2e-apt can easily be installed from the m2e discovery dialog in Eclipse (“Window” → “Preferences” → “Maven” → “Discovery” → “Open Catalog”). Then turn the connector on at “Window” → “Preferences” → “Maven” → “Annotation Processing”. When you now update your Maven project (right click on the project and select “Maven” → “Update Project…”), then annotation processing for the Eclipse project should be automatically configured in the dialog you have described in your question.

like image 131
Chriki Avatar answered Oct 13 '22 09:10

Chriki