[jboss-user] [Javassist user questions] - Using Javassist inside Mojo
ad-rocha
do-not-reply at jboss.com
Tue Jun 2 15:34:53 EDT 2009
Hi all,
I´m trying to use Javassist inside a Mojo. The code is very simple, but the program fails with a java.lang.ClassNotFoundException.
First I collect all dependencies of Maven project:
| // maven dependencies
| List<String> classpath = new ArrayList<String>();
| classpath.addAll(project.getCompileClasspathElements());
| classpath.addAll(project.getTestClasspathElements());
| Set<Artifact> artifacts = project.getDependencyArtifacts();
| for (Artifact artifact : artifacts) {
| classpath.add(artifact.getFile().getAbsolutePath());
| }
|
After that, I append all dependencies to ClassPool:
| ClassPool pool = ClassPool.getDefault();
| // add dependencies to classpath
| for (String element : classpath) {
| pool.appendClassPath(element);
| }
| // get class
| CtClass cc = pool.get(className);
|
The error is caused by method.getAnnotations() call below:
| ...
| if (object instanceof CtMethod) {
| CtMethod method = (CtMethod) object;
| annotations = method.getAnnotations();
| ...
| }
|
The error is: java.lang.ClassNotFoundException: org.testng.annotations.BeforeMethod
But, org.testng.annotations.BeforeMethod is inside testng-5.8-jdk15.jar, wich was added to classpath. What am I doing wrong?
Thanks in advance,
Andre
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4234800#4234800
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4234800
More information about the jboss-user
mailing list