aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Problem with processing runtime Annotation in mojo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Problem with processing runtime Annotation in mojo" Watch "Problem with processing runtime Annotation in mojo" New topic
Author

Problem with processing runtime Annotation in mojo

Andreas Joerg
Greenhorn

Joined: Oct 11, 2012
Posts: 2
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?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

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

JBoss In Action
Andreas Joerg
Greenhorn

Joined: Oct 11, 2012
Posts: 2
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.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

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.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with processing runtime Annotation in mojo
 
Similar Threads
How do I process compile time annotations from a Mojo
Calling a custom maven plugin
Maven 1 to Maven 2 upgrade
Plugin execution not covered by lifecycle configuration
maven calling an ant target