0

I wrote an aspect to print details about Method whenver any method calls any another method. I want to exclude java libraries.

I am trying to weave aspect to a jAR file and then execute the JAR.

I am struggling from long and read many tutorials but can’t accomplish task.

Here’s code for 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");
    }

}

Command I used to generate weaved jar

ajc -injars dacapo-9.12-bach.jar aspects/MethodCallProfile.aj -outjar weaved_aspect.jar -classpath "aspectjrt.jar" -Xlintfile ajc.properties

Command I tried to execute weaved 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

Error

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 more

Ajc.properties file (As I was getting errors when it couldn’t find certain types.

cantFindType = warning
user1568701
  • 43
  • 3
  • 11

1 Answers1

0

My problem is solved. I read readme file in aspect1.8 directory and followed steps.

I copied aspectjrt.jar to the jdk/jre/lib/ext directory and added aspectjrt.jar to my CLASSPATH environment variable.

While compiling i added -cp .;

user1568701
  • 43
  • 3
  • 11
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - [From Review](/review/low-quality-posts/10594056) – honk Dec 17 '15 at 07:42
  • I added it as answer as this solved my problem now I can compile and execute code – user1568701 Dec 17 '15 at 16:29
  • I'm sorry, your answer looked like additional information on your question. Could you maybe [edit](http://stackoverflow.com/posts/34327474/edit) your answer and make more clear that what you did solves your problem? – honk Dec 17 '15 at 19:49