java - How to attach a pointcut to a to a method of class residing inside a .jar file using command line? -


i new aop . have created class in hookshow.java file:

public class hookshow {         void show(string msg)         {             system.out.println("in show :"+msg);         }         public static void main(string[] args)         {             hookshow cm=new hookshow();             cm.show("called main method");          } } 

then compiled , added generated .class file .jar file using :

jar cf hshow.jar hookshow.class 

now have hshow.jar. creating aspect has pointcut executed on call of show(). dont have idea how can reffer class , method inside jar file. following aspect file:

public aspect aspecthookshow {    pointcut changemsgpointcut( string str) :execution(void hookshow.show(string)) && args(str);     before(string str ) : changemsgpointcut( str)    {       system.out.println("inside pointcut :"+str);    }     } 

so please can tell me how can reffer method inside class in jar file.

after research of 3 hours found 3 ways achive mentioned above, thing had not change code , needed execute commands on cmd prompt :

first way:

i got 1 way oreilly aspectj cookbook :

steps: 1:compile hookshow class using traditional javac command:

javac hookshow.java 

2:package generated hookshow.class file .jar file titled myapp.jar:

jar -cvf myapp.jar hookshow.class

3:compile aspecthookshow.java aspect using ajc command, specifying new myapp.jar on command line using -inpath option:

> ajc -inpath myapp.jar aspecthookshow.java 

the -inpath option forces ajc compiler extract java byte code supplied .jar files destination directory specified -d option. ajc compiler includes extracted byte code in aspect weaving process.

4:if no errors occur during compilation ajc have woven classes contained within myapp.jar file aspecthookshow aspect. because ajc command extracts classes .jar files supplied -inpath option, no longer needed run application. however, can optionally re-package new application in .jar file of own using -outjar option when running ajc command:

> ajc  -inpath myapp.jar -outjar myaspectorientedapp.jar aspecthookshow.java 

this produces myaspectorientedapp.jar contains application's aspects , classes can run using traditional java command:

> java -classpath myaspectorientedapp.jar hookshow 

second way:

execute following command:

>ajc -janars aspectjrt.jar ;hshow.jar aspecthookshow.java -outjar final.jar 

this create final.jar. put jar in classpath , m able use in class.

hope useful else me.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -