[ImageJ-devel] Why Eclipse ignores SezPoz and NetBeans Lookup annotations

Curtis Rueden ctrueden at wisc.edu
Mon Jan 31 17:55:09 CST 2011


Hi everyone,

Recently I did some digging into a problem we have been having: when
compiling ImageJDev code inside Eclipse, it does not execute annotation
processors. The result is that when running ImageJ2 from Eclipse, none of
the dependency injection works—no IJ2 plugins are discovered, etc.

DETAILS:

Both SezPoz and NetBeans Lookup make use of annotation processors—listed in
the relevant JARs' META-INF/services/javax.annotation.processing.Processor
file—to write additional information to the target project's META-INF
directory. For example, in the case of NetBeans Lookup, it adds the class to
the META-INF/services/whatever-service file.

It turns out that unlike Javac and NetBeans, Eclipse does not enable
annotation processing by default. And there is no way to turn it on by
default—it must be enabled on a project-by-project basis. Further, JARs
containing relevant annotation processors must then be explicitly listed in
the project configuration under Java Compiler > Annotation Processing >
Factory Path.

The SezPoz homepage makes mention of these facts, as follows:

Eclipse-specific notes: make sure annotation processing is enabled at least
for any projects registering objects using annotations. Make sure the SezPoz
library is in the factory path for annotation processors. You also need to
check the box *Run this container's processor in batch mode* from the *
Advanced* button in *Java Compiler > Annotation Processing > Factory Path*.
There does not appear to be any way for Eclipse to discover processors in
the regular classpath as JSR 269 suggests, and there does not appear to be
any way to make these settings apply automatically to all projects. Eclipse
users are recommended to use javac (e.g. via Maven) to build. Eclipse Help
Page<http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_apt_getting_started.htm>
Eclipse
bug #280542 <https://bugs.eclipse.org/bugs/show_bug.cgi?id=280542>

Further, if anything goes wrong during annotation processing, Eclipse logs
the error to .metadata/.log in its workspace, but does not report the
problem in the user interface, making debugging difficult.

SOLUTION:

We could make SezPoz work automatically from Eclipse by committing certain
metadata files to the repository. However, there is a further problem with
using NetBeans Lookup from Eclipse: it throws a cryptic exception (to the
.metadata/.log) when its annotation processor is invoked. Hence, NetBeans
Lookup still won't work properly, even with Eclipse properly configured.

So for now, the easiest way to run ImageJ2 is to do a clean build by
invoking Maven, and then running a simple shell script:

$ mvn -DskipTests clean install
$ cd imagej
$ ./run

In conclusion, this bug,
#280542<https://bugs.eclipse.org/bugs/show_bug.cgi?id=280542>,
is a serious limitation in Eclipse, and I encourage any interested
developers to vote for a resolution.

-Curtis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20110131/c951a051/attachment.html>


More information about the ImageJ-devel mailing list