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.

  1. Download the latest version of Smith at the project page and unpack the zip file
  2. Run the command:
    ant dist

  3. Check the dist folder for smith-${version}.jar
  4. Download the test classes and unpack the zip file
  5. Compile them with
    javac Main.java

  6. 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 second

    Bar: I’m doing something
    Bar$Foo: What else???

  7. Now open another console and go to the test classes source folder
  8. Edit file Bar.java and change the two text printed by System.out.println
  9. Compile Bar.java with javac
  10. 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.

Leave a Reply