Agent Smith: how to compile and test it
Following my previous post, in the agent smith post series.
Smith comes in two versions: one is java5 only, the other is java6+, meaning you must have at least java 6 (or mustang) to run it.
The two versions differ in one feature only: the ability to load the agent after the jvm start up, instead of the usual way that’s by specifying it with a command line parameter. Anyway, such feature is experimental (even if I use it daily).
Let’s see what to do to begin using Smith.
- Download the latest version of Smith at the project page and unpack the zip file
- Run the command:
ant dist
- Check the dist folder for smith-${version}.jar
- Download the test classes and unpack the zip file
- Compile them with
javac Main.java
- Run them with
java -javaagent:<PATH_TO_SMITH_JAR>=<PATH_TO_CURRENT_FOLDER> Main
Every path must be absolute.
You should see two messages repeating every one secondBar: I’m doing something
Bar$Foo: What else??? - Now open another console and go to the test classes source folder
- Edit file Bar.java and change the two text printed by System.out.println
- Compile Bar.java with javac
- Check the first console: do you see the messages changed?
Easier done than said :)
Next time we’ll set up Tomcat to use Smith into a webapp.