Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run java annotation processor

I am having troubles running my annotation processor from command line. The problem is that it works in Windows environment, but not on my linux installation.

My processor is located in a jar file (meta-validator.jar). I also added entry to META-INF/services/javax.annotation.processing.Processor containing fully qualified name of class of my processor.

I am trying to invoke annotation processor with this command:

javac -cp "./metadata-validator.jar; ... (path to annotations.jar etc.)" -processor xammt.validator.modules.ValidatorModule -proc:only " ... path to sources" 

In Windows environment it just works (Windows 7 64bit Pro, JDK 1.7.xx), processor is found and process method is executed.

In my linux environment (Linux Mint 13 32bit -> basically Ubuntu 12.04, Oracle JDK 1.7) I get message:

error: Annotation processor 'xammt.validator.modules.ValidatorModule' not found
warning: Annotation processing without compilation requested but no processors were found.

Also without -processor switch I get the same warning (with other verbose stuff).

What could be causing this problem? I guess that my JDK on linux machine is installed correctly, because I am able to run/compile java applications without any problems.

Thanks for any advice.

EDIT: I have still no idea why this does not work. Funny thing is, that it works programmatically - I managed to invoke my annotation processor via Java Compiler API without problems (on both platforms), this is also better solution because of debugging.

EDIT2: Actual command:

javac -cp "./metadata-validator.jar;./lib/common-library.jar;./Annotation source.jar" 
-processor xammt.validator.modules.ValidatorModule -proc:only "SourceFile.java"

SOLVED: check http://en.wikipedia.org/wiki/Classpath_(Java)#OS_specific_notes

like image 477
Brand88 Avatar asked Dec 16 '12 01:12

Brand88


2 Answers

On Linux are you using colon instead of semicolon as your class path separator? Include the Linux command you are executing as well.

Change the semi-colons to colons in the classpath and it should work.

Like this:

javac -cp "./metadata-validator.jar:./lib/common-library.jar:./Annotation source.jar" -processor xammt.validator.modules.ValidatorModule -proc:only "SourceFile.java"
like image 69
Jeff Putney Avatar answered Sep 20 '22 16:09

Jeff Putney


I also found out that the version of OpenJDK 7 included in Debian Wheezy (7u3) simply does not work with annotation processors. I did a custom build of OpenJDK 7u9 (from Ubuntu Quantal) and it works perfectly.

I reported a bug in Debian's bugtracker: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697658

like image 32
Ricardo Pardini Avatar answered Sep 21 '22 16:09

Ricardo Pardini