akula1001
akula1001

Reputation: 4636

unable to resolve jar dependencies for annotation processor

I have an annotation processor that depends on an external jar - lib.jar I'm packaging my processor as a jar and using it while compiling my client. I had it working fine until I introduced lib.jar when the client compilation started failing with this message.

Exception thrown while constructing Processor object: java.lang.NoClassDefFoundError: com/foo/FooBar

I tried placing lib.jar in the classpath for my client but it didn't help. What am I missing?

Upvotes: 2

Views: 4018

Answers (2)

kiki
kiki

Reputation: 243

(a bit late)

The search path is explained here : http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html#processing

and it seems that dependencies only need to be in the classpath.

with maven:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
    <annotationProcessors>
      <annotationProcessor>
        *your annotation class qualified name*
      </annotationProcessor>
    </annotationProcessors>
  </configuration>
</plugin>

plus the dependency to the annotation processor artifact.

I had this issue in eclipse IDE to use an annotation processor having external dependencies.

To solve his you can build a jar-with-dependencies lib to be used in Eclipse IDE.

Upvotes: 0

David Chandler
David Chandler

Reputation: 2417

Add lib.jar to your annotation factory classpath in addition to your processor jar. In Eclipse, it's under project properties, Java Compiler, Annotation Processing, Factory Path.

Upvotes: 3

Related Questions