Forums Register Login

Problem with processing runtime Annotation in mojo

+Pie Number of slices to send: Send
Hi,

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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I'm using Eclipse (indigo) and M2E.

1. process-classes
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

If you want to i can upload the eclipse projects.
+Pie Number of slices to send: Send
 

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.)
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 879 times.
Similar Threads
maven calling an ant target
Plugin execution not covered by lifecycle configuration
How do I process compile time annotations from a Mojo
Maven 1 to Maven 2 upgrade
Calling a custom maven plugin
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:36:45.