Aspectj编织外部罐子 [英] Aspectj in weaving external jar
问题描述
我有一个如下的Java文件
package sample;
public class Profile
{
public static String myName(String name)
{
myhobby("Football");
return name;
}
public static String myhobby(String hobby)
{
return hobby;
}
}
我构建了这个文件,并将jar文件添加到以下代码中...
导入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");
}
}
我写的方面如下...
pointcut printMessage(String name) : call(public static String myhobby(..)) && args (name));
before(String name) : printMessage(name) {
System.out.println("value is: "+ name);
}
但是,当我运行程序时,它没有打印出业余爱好的参数值... 如果我错了,谁能纠正我... 预先感谢...
默认情况下,AspectJ IDE仅将当前项目与相同项目的各个方面编织在一起,对于其他场景,我们需要为该项目添加In-Path或Aspect-Path./p>
从第二个项目(您的测试项目)的属性"对话框>"AspectJ Build"页面> InPath中,将您的jar添加到列表(该jar同时自动添加到Java Build Path库中).
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...
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).
这篇关于Aspectj编织外部罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!