title: How to use ByteBuddy in a java project
body: <p>I made a simple project of java to test ByteBuddy . I typed exactly the same code in a tutorial made by Rafael Winterhalter but it showing some errors </p>
  
  <pre><code>    1) ByteBuddyAgent cannot be resolved.
      2) type cannot be resolved to a variable.
      3) builder cannot be resolved.
      4) method cannot be resolved to a variable.
  </code></pre>
  
  <p>I added the byte-buddy-1.7.1.jar as a referenced library.  </p>
  
  <pre><code>public class LogAspect {
  
  public static void main(String[] args){
      premain("", ByteBuddyAgent.installOnOpenJDK());
      Calculator calculator = new Calculator();
      int sum  = calculator.sum(10, 15, 20);
      System.out.println("Sum is "+ sum);
  }
  
  public static void premain(String arg, Instrumentation inst){
  
      new AgentBuilder.Default()
      .rebase(type -&gt; type.getSimpleName().equals("Calculator"))
      .transform((builder, typeDescription) -&gt; builder
              .method(method -&gt; method.getDeclaredAnnotations().isAnnotationPresent(Log.class))
              .intercept(MethodDelegation.to(LogAspect.class).andThen(SuperMethodCall.INSTANCE)))
              .installOn(inst);
  }
  
  
  public static void intercept(@Origin Method method){
      System.out.println(method.getName()+" is called.");
  }
  
  }
  
  @interface Log{
  
  }
  
  class Calculator {
  @Log
  public int sum(int... values) {
  
      return Arrays.stream(values).sum();
  }
  
  }
  </code></pre>