[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] add aspect without source
|
Here's a very short tutorial on how to use ajc to weave into existing
.class files.
===============================================================
Step 1. Make hello.jar
File Hello.java
--------------------
public class Hello {
public static void main(String[] args) {
System.out.println("hello world");
}
}
--------------------
> javac Hello.java
> jar -cf hello.jar Hello.class
> java -classpath hello.jar Hello
hello world
===============================================================
Step 2. Weave in a simple tracing aspect
File Trace.aj
--------------------
public aspect Trace {
before(): execution(* Hello.*(..)) {
System.out.println("entering: " + thisJoinPoint.toString());
}
}
--------------------
> ajc Trace.aj -injars hello.jar -outjar trace-hello.jar
> java -classpath trace-hello.jar;<path-to-lib>\aspectjrt.jar Hello
entering: execution(void Hello.main(String[]))
hello world
=================================================================
Does this help? If you're still have problems please try to provide as
concrete and detailed an example as possible to help us understand what
you're trying to do.
-Jim