I have a jar with a main class.
I execute it with command java -jar my.jar
This main jar depends on another.jar
(e.g. joda-time.jar
).
Now I want to intercept a method of another.jar
and say I want to print log.
By the way, I want to use my.jar
as usual, I mean I'll call it as always: java -jar my.jar
.
I have found a very nice example on github about external library weaving.
This example, intercepts a method of joda time library.
It has an aspect for toString()
method of joda time.
However, it uses a unit test to intercept and demonstrate.
I've compiled and packed the given example as my_aspect.jar
.
After that, I've moved my_aspect.jar
to the execution directory, which contains my.jar
, joda-time.jar
.
Finally, I've also added aspectjrt.jar
, and aspectjweaver.jar
to the same directory.
When I call java -jar my.jar
, intercepiton doesn't happen.
I think I have to tell the my_aspect.jar
something to intercept but I don't know what to say.
Below is the main class of my.jar.
It simply makes a call to intercepted method.
package com.github.example;
import org.joda.time.DateTime;
public class Main {
public static void main(String[] args) {
System.out.println(new DateTime().toString());
}
}