我写了一个方面,当任何方法调用任何另一个方法时,打印有关方法的详细信息。我想排除java库。
我正在尝试将方面编织到JAR文件中,然后执行jAR。
我苦苦挣扎了很久,读了很多教程,却无法完成任务。
以下是aspect的代码
import org.aspectj.lang.Signature;
public aspect MethodCallProfile {
pointcut tracedCall() : call (* *(..)) && ! within(MethodCallProfile) ;
pointcut exclude() : execution(* java*(..)) && !within(MethodCallProfile) ;
before() : tracedCall() && exclude() {
Signature sig = thisJoinPointStaticPart.getSignature();
String line = ""
+ thisJoinPointStaticPart.getSourceLocation().getLine();
String sourceName = thisJoinPointStaticPart.getSourceLocation()
.getWithinType().getCanonicalName();
//
System.out.println("Call from " + sourceName + " line " + line + "\n to "
+ sig.getDeclaringTypeName() + "." + sig.getName() +"\n");
}
}我用来生成编织jar的命令
ajc -injars dacapo-9.12-bach.jar aspects/MethodCallProfile.aj -outjar weaved_aspect.jar -classpath "aspectjrt.jar" -Xlintfile ajc.properties命令我尝试执行编织JAR
aj -cp .;;d:\dacapo\lib\aspectjweaver.jar -jar weaved_dacapo.jar avrora
java -cp d:\dacapo\lib\aspectjrt.jar;d:\dacapo\lib\aspectjtools.jar;d:\dacapo\lib\aspectjweaver.jar;d:\dacapo\lib\org.aspectj.matcher.jar -jar weaved_dacapo.jar avrora错误
Exception in thread "main" java.lang.NoClassDefFoundError:
org/aspectj/lang/Signature
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getMethod0(Class.java:2764)
at java.lang.Class.getMethod(Class.java:1653)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.Signature
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 moreAjc.properties文件(因为我在找不到某些类型时收到错误。
cantFindType = warning发布于 2015-12-17 13:48:53
我的问题解决了。我阅读了aspect1.8目录中的自述文件,并遵循了以下步骤。
我将aspectjrt.jar复制到jdk/jre/lib/ext目录,并将aspectjrt.jar添加到我的CLASSPATH环境变量中。
在编译时,我添加了-cp。
https://stackoverflow.com/questions/34161219
复制相似问题