Home Ask Login Register

Developers Planet

Your answer is one click away!

jrad February 2016

Annotation Processing Tool add code to existing class

My goal is to add some source code to existing class using annotations.

First, I create an annotation and then I implemented a AbstractProcessor Class. After that I create the javax.annotation.processing.Processor file and I generate the JAR file using the export eclipse option.

javax.annotation.processing.Processor file

When I use my jar in other project I have the following error:

Internal compiler error: java.lang.NoClassDefFoundError: com/sun/source/util/Trees at org.xxx.preprocessor.ActionProcessor.init(ActionProcessor.java:44)

And the mentioned line is like the joined picture:


I want to use tree in order to get the compilation unit and add some code to my annotated function.

So in the first time I don't know how to fix this problem, or another way to do this.


Aaron Digulla February 2016

You wrote an AP tool which is based on Sun internal code but run it inside of the Eclipse IDE. Eclipse comes with it's own Java compiler, so you don't have access to internal Java classes anymore.

I suggest to look at Project Lombok which has the exact same problem and look at their solution. The source hides behind the "Contribute" link: https://github.com/rzwitserloot/lombok

In the src/ folder is a folder eclipseAgent/ which should get you started.

Post Status

Asked in February 2016
Viewed 3,641 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life