How to run annotation handler in eclipse when saving

I am currently creating files with an annotation processor in eclipse for a project

Right click on project > Run As > Maven Clean Right click on project > Run As > Maven install 

It takes a lot of time. How to configure eclipse to make it run annotation handler when saving?

I have a Build Automatically feature, but it seems to ignore annotation processors. BTW I am using the m2e apt plugin with "JTT APT auto tuning activated."

+6
source share
3 answers

I think you need a trigger to trigger the Maven, So target:

You must add a valid maven lifecycle action

Example for a jar that automatically deploys locally to maven install plugin :

 <build> <!-- ... --> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <versionRange>[2.0,)</versionRange> <goals> <goal>jar</goal> </goals> </pluginExecutionFilter> <action> <execute> <runOnConfiguration>true</runOnConfiguration> <runOnIncremental>true</runOnIncremental> </execute> </action> </pluginExecution> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <versionRange>[2.5.0,)</versionRange> <goals> <goal>install</goal> </goals> </pluginExecutionFilter> <action> <execute> <runOnConfiguration>true</runOnConfiguration> <runOnIncremental>true</runOnIncremental> </execute> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> </build> 

Hint: refers to Maven Project Builder is called every time the source file (GWT) changes and as a warning: the installation usually includes tests if you included them in your normal maven build cycle

+1
source

I have annotation processing working in Eclipse for some of my projects; for me it works on saving, and I don't need mvn install (and it works differently than Maven, since Eclipse runs its own compiler).

I also use the m2e-apt plugin for this. As noted above, Eclipse launches its own compiler; this means that its output may be slightly different from Maven (when you "Right-click on the project> Run as> Maven Clean / Install" you call Maven, not Eclipse). I mention this because it is possible that your processors have problems and work in Maven, but not in Eclipse (although most of the time they produce the same output, I saw some differences, but very small ones). I would follow the Eclipse error log if I were you (because annotation processing errors are written there).

So here is what I suggest:

  • Publish an image with Maven / Annotation Processing settings to Eclipse (even if you have the correct activation option).
  • Place a snapshot with the Java/Compiler settings (there is a checkmark that must be activated, it does not work without).
  • pom.xml will be, oddly enough, useful. Especially if you have a custom configuration for maven-compiler-plugin . Some of these configurations are interpreted by m2e-apt , for example, compiler arguments.
  • Locate the file called .factorypath . That m2e-apt stores a list of banners that it scans for processing annotations (you will find there all the banks of your project, even if they actually do not contain processors, that is, if your maven-compiler-plugin not configured as such, consider only specific list of processors). If the jug containing your processor is not in the .factorypath , it will not work.
  • Last but not least, there is one more thing that can cause problems. If the project containing the actual annotation processor (so NOT the client) is in the same workspace as the client project, then m2e-apt will simply ignore your annotation processor; I do not know why. Closing your annotation processor project would be sufficient in this case (you do not need to remove it from the workspace).

Edit: Forgot to say that if you are processing annotations through Maven (and you only call Maven to process annotations) then mvn compile should be enough. In addition, you do not need to run it separately (first mvn clean , then mvn compile ). You can run it in one shot using mvn clean compile ; it should have the same effect.

+1
source

Make sure that your Java project settings (accessible by right-clicking on the project > Java compiler > Annotation processors ) activate annotation processing and that the settings meet your expectations.

For a Maven project, m2e must correctly configure these parameters according to the contents of pom.xml. However, this does not work smoothly for all Maven plugins (some of them will be supported out of the box, some others will require a specific plugin ...).

+1
source

All Articles