Aspectj in weaving external jar

2019-09-17 07:01发布

问题:

I have a java file as follows

package sample;
    public class Profile

    {


    public static String myName(String name)
    {
        myhobby("Football");
        return name;
    }
        public static String myhobby(String hobby)
    {


        return hobby;
    }

    }

I build this file and added the jar file into the below code...

import sample.Profile;

  public class Hello

    {

        public static String sayHello(String name)
        {

            String enter=Test.myName("Ganguly");
            return name;
        }

        public static void main(String[] args)
        {
        String next =   sayHello("Company");

        }
    }

And I wrote aspect as follows...

pointcut printMessage(String name) : call(public static String myhobby(..)) && args (name));
     before(String name) : printMessage(name) {
            System.out.println("value is: "+ name);

     }

But when I run the program...it doesn't printed the parameter value of the function hobby... can any one correct me if I am wrong... Thanks in advance...

回答1:

By default, AspectJ IDE only weave current project with aspects of same project, we need add In-Path or Aspect-Path for the project for other scenarios.

From Properties dialog of the second project (your testing project) > 'AspectJ Build' page > InPath , add your jar to the list (the jar is added to Java Build Path library automatically at same time).



标签: java aspectj