1

I am running Eclipse Luna (4.4.1) under Ubuntu 14.10 (Utopic Unicorn) and have a project that uses annotation processing to validate certain forms in the code and generate utility code. In eclipse the code is not being generated.

First, the processors work perfectly with javac. Second the processors DO run in Eclipse. If I alter them to throw exceptions Eclipse reports that. Also if I provide the processors with malformed code (such as a getter/setter pair with different types) it reports the error properly (red squiggles, proper error message, whole nine yards).

No code appears in .apt_generated nor are class files generated.

I've tried disabling them and re-enabling them, starting a new project, tried it on a fresh install of Eclipse, changing the project version from 1.7 to 1.8 and back again, tried batch mode and not batch mode, changing the .apt_generated directory, double checked the permissions on .apt_generated, probably a few other things that I can't recall.

At this point I'm just running javac separately and thinking about making this our first Apache Ant or Maven project if that would help but I'd rather not quite at this juncture.

Anyone have any luck with code generation within Eclipse? Anything else to do or check?

electroCutie
  • 194
  • 1
  • 8

2 Answers2

2
  • Verify your project is set to actually use APT, as shown in https://www.eclipse.org/jdt/apt/introToAPT.php. Be aware those are project settings, not workspace preferences.
  • Make sure your potentially generated code is not deleted by some other part of your workflow. E.g. a second processor cleaning the directory that a first processor generated into.
  • Check that you are using a JDT and not a JRE both for running Eclipse as well as building your project.
  • Verify that org.eclipse.jdt.apt.core is part of your Eclipse installation, as that is the actual annotation processor integration for the JDT.
  • Verify your processor has a correctly filled file META-INF/services/javax.annotation.processing.Processor, pointing to the right class implementing the processor. Eclipse may ignore it otherwise.

That being said, I have used different annotation processors (like butterknife for Android) in Eclipse over the years and didn't run into such problems.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • As i said, the processors are running in Eclipse. Confirmed because the processors do set errors in the code where appropriate with [Messager.printMessage()](http://docs.oracle.com/javase/7/docs/api/javax/annotation/processing/Messager.html#printMessage%28javax.tools.Diagnostic.Kind,%20java.lang.CharSequence,%20javax.lang.model.element.Element%29) – electroCutie Jan 05 '15 at 16:26
  • Oh, and to ameliorate your other concern, that another processor is nuking the directory I do not believe that to be the case. Not only are there no other processors running but the directory, when populated by javac, is not cleaned out even by a full rebuild in eclipse. While not absolute proof I feel it is fairly conclusive. – electroCutie Jan 05 '15 at 18:43
0

I had a similar problem with the AutoValue annotations not being processed with Eclipse 2019-3 with OpenJDK 11 as target runtime. In the Eclipse "Error Log" panel I saw this error:

java.lang.Exception: java.lang.UnsupportedClassVersionError:
javax/lang/model/element/ModuleElement has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Eclipse was running on an old Java 8 installation as indicated by Help -> About Eclipse IDE -> Installation Details -> Configuration. In my case, Eclipse found the JRE to run on on the PATH environment variable, see here. I forced Eclipse to use the OpenJDK 11 installation by adding the -vm argument to the Eclipse.ini:

-vm
"C:\path\to\OpenJDK\bin\server\jvm.dll"
Dennie
  • 890
  • 12
  • 16