Aspectj in weaving external jar

人盡茶涼 提交于 2019-12-12 04:45:26

问题


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).



来源:https://stackoverflow.com/questions/26292385/aspectj-in-weaving-external-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!