Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] load-time weaving from code

Hi, I need to perform Load-Time Weaving from Java code. I'm using the WeavingURLClassLoader, but it doesn't work. How must I go on? I get the following code:

            URL[] classesPath = getClasspath("MyMainClass", "MyAspect.jar", "lib/aspectjrt.jar");
            URL[] aspectsPath = getClasspath("myAspect.jar");
       
            WeavingURLClassLoader weavingClassLoader = new WeavingURLClassLoader(classesPath , aspectsPath , Thread.currentThread().getContextClassLoader());
            Thread.currentThread().setContextClassLoader(weavingClassLoader);
           
            Class main = weavingClassLoader.loadClass("MyMainClass");

            Object app = main.newInstance();

            if (main != null) {
                Method init = main.getMethod("myMethod", null);
                init.invoke(app, (Object[])null);
            }   

The Java application works but the aspect is not woven.

Additionally, I also tried including the following properties:

            System.getProperties().setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH, myAspectPath);
            System.getProperties().setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH, myClassPath);
            System.getProperties().setProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true");
            System.getProperties().setProperty(WeavingAdaptor.SHOW_WEAVE_INFO_PROPERTY,"true");
            System.getProperties().setProperty(WeavingAdaptor.TRACE_MESSAGES_PROPERTY,"true");

and the provided info shows that the aspect library is added correctly, but the aspect is not woven either.

If I execute the Java application as an "AspectJ Load-Time Weaving Application" in eclipse with arguments -javaagent:lib/aspectjweaver.jar and indicating the aspect in the LTW Aspectpath, the application works perfectly and the aspect is woven; but I need to performs this from code.

I'm using the JDK 1.7.

Thanks in advance.

 

Regards,

José Miguel.


Back to the top