Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] problems using LTW and WeavingClassLoader

Hi  Ramnivas, 
                      I changed the call to execution() and it worked !!!! ... Thank a lot :) 

On Sat, Oct 2, 2010 at 11:50 PM, Ramnivas Laddad <ramnivas@xxxxxxxxxxxxxxx> wrote:
Your call is through reflection and thus won't match the pointcut you specified. You need to either change pointcut to select reflection api or use execution() to select the execution side of the method.

Also, you should first try using compile-time weaving right inside Eclipse to ensure that your pointcut is correct.

-Ramnivas


On Sat, Oct 2, 2010 at 9:53 AM, atharva chauthaiwale <atharva.chau@xxxxxxxxx> wrote:
Hi all,  
         I think this question has already been asked on this mailing list but I could not find satisfactory answer.. So here is my problem...

I am trying to use LTW using command line aj script as follows :

I have
 Aspect file : TraceAspect.aj  

public aspect TraceAspect {

pointcut trace()
: call (* *.printH*(..));
before() : trace() {
System.out.println("Printing from aspects :  hello...................");
}
}


 java file : Hello.java 

public class Hello{
int i;
String s;
Hello()
{
this.i=0;
this.s="";
}
public void printHello()
{
System.out.println("hello  from printHello" );
}
}


Main.java :

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 *
 * @author lnvidyad
 */
public class Main {

    public static void main(String[] args) {

 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
 System.out.println("my loader " + classLoader.toString() );
        try {
            //load class...
            
Class myClass = classLoader.loadClass("hello");
            System.out.println("Class loaded:" + myClass.getName());

            //get the array of methods...
            Method m[] = myClass.getMethods();

            //make object...
            Object p = null;
            try {
                //actually, make object here...
                p = myClass.newInstance();

                try {
                    //invoke the first method...
                    m[0].invoke(p,null);
                } catch (IllegalAccessException ex) {
                    ex.printStackTrace();
                } catch (IllegalArgumentException ex) {
                    ex.printStackTrace();
                } catch (InvocationTargetException ex) {
                    ex.printStackTrace();
                }

            } catch (InstantiationException ex) {
                ex.printStackTrace();
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}


basically i want to use WeavingURLClassLoader at runtime to load my classes just like URLCLassLoader

So , I did following steps: (all files in same directory)

1.  ajc TraceAspect.java -outjar tracelib.jar
2.  ajc Hello.java
3.  ajc Main.java

4. set ASPECTPATH=tracelib.jar
5. aj Hello                         


Since aj replaces system classloader with WeavingURLCLassLoader, when I load Hello class  it should also perform weaving of TraceAspect
However, TraceAspect is not getting woven and hence I am not able to print message from TraceAspect...  

1. Can someone please explain me what is the problem ?
2 .What is the alternate way of using  WeavingURLClassLoader at runtime ? 

Thanks 

Regards,
Atharva


_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top