Hi,
I've been having some problems with using plugins to generate extra
artifacts based on annotations in some classes. Simply the plugin
hasn't been able to read any annotations from a class loaded using an
URLClassLoader. For example:
Outside a plugin:
public class NoPlugin
{
public static void main( String[] args )
{
try {
File f = new File("/workplace/java-studies/annotations-
bug/annotation-direct/target/annotation-direct-1.0-SNAPSHOT.jar");
URLClassLoader cload = new URLClassLoader(new URL[]
{f.toURL()},ClassLoader.getSystemClassLoader());
Class cl = cload.loadClass("InterfaceToUse");
Method m = cl.getMethod("interface1");
System.out.println("Annotation is present? " +
m.isAnnotationPresent(MyAnnotation.class));
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
}
The result is:
Annotation is present? true
Now inside a plugin:
public class TestMojo extends AbstractMojo
{
public void execute() throws MojoExecutionException
{
try {
File f = new File("/workplace/java-studies/annotations-
bug/annotation-direct/target/annotation-direct-1.0-SNAPSHOT.jar");
URLClassLoader cload = new URLClassLoader(new URL[]
{f.toURL()},ClassLoader.getSystemClassLoader());
Class cl = cload.loadClass("InterfaceToUse");
Method m = cl.getMethod("interface1");
getLog().info("Annotation is present? " +
m.isAnnotationPresent(MyAnnotation.class));
} catch (Exception e) {
getLog().error("Exception: " + e.getMessage());
}
}
}
The result is:
Annotation is present? false
Is there anything I'm missing here?
Thank you,
Michel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]