i want to develope an maven plugin for automatic code generating.
I have an Annotation that can be set for methods its Retention is RUNTIME.
Whenever this annotation is set for a method i want to generate an constant value with the methodName in another class.
When i run the generator standalone everything works fine.
But when i call the generator from my mojo the annotation cant be processed. For debugging i have thrown an exception with the count of annotations for the method as Exceptionmsg. It was 0. Executing the same code standalone results in an Exception with message 1.
So why cant the annotation be processed by the generator when running as maven plugin?
1) What lifecycle phase is your mojo connected to?
2) Have you tried doing a binary compare of the .class files generated by the standalone compiler and by the Maven? (They should be the same)
3) Does your code get the class file from the JAR or just from disk?
4) Try adding -verbose:class to the java command line within the mvn startup script (or better yet, create setenv.bat and in there set MVN_OPTS to -verbose:class - see the mvn script for details) (by the way, what OS are you running). This option causes the JVM to print out the locations for reach classfile loaded, perhaps that will give you some idea of what went wrong - perhaps the wrong class is being loaded
2. not necessary cause the class file is generated always the same way (eclipse compiler)
3. I'm loading the class file from disk using the URLClassLoader.
4. I don't think that this could be a problem see 3. The Class is loaded from disk path. Maybe an other URLClassLoader is used?
My OS is Windows XP but fails also on Windows7
Andreas Joerg wrote:I'm using Eclipse (indigo) and M2E.
That's your first problem. Try running the build from a command line. m2eclipse does funny things to the build plan and can wreak havoc.
2) For a maven build the class should not be created by the Eclipse compiler. Exactly how were you building within Eclipse? By doing Run As | Maven Package (or something similar), I hope. Doing an Eclipse build will not run the Maven build (as far as I know).
4) I still think you are picking up an incorrect copy of the .class file, dumping out which .class file you are getting is the first step in debugging this issue. (The first step is making sure you have the right .class file) Dumping out the raw class contents within your code would be the second step in debugging. (The second step is making sure that your code sees the same raw class contents when running as a plugin and standalone.)
subject: Problem with processing runtime Annotation in mojo