2

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:

ActionProcessor.java:44

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.

1
  • Please include the code as text in the question, not as pictures. Commented Feb 8, 2016 at 15:16

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your response, So if I use the javac commande : > javac -cp myExported.jar SimpleAnnotationsTest.java it'll work !! Because I get JavaModelException
@jrad You're getting a different exception, so I'd say yes, my answer is correct. If you want to know why you're getting JavaModelException, you have to ask a new question and give us all the details.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.