title: "Failed to load Premain-Class manifest attribute" while trying to get the size of an object using java agent
body: <p>When i try to run a java program (<code>java -javaagent:size.jar ObjectSizeTest</code>) i get the following error:</p>
  
  <pre><code>Failed to load Premain-Class manifest attribute from D:\workspace\ObjectSizeTest\size.jar
  Error occurred during initialization of VM
  agent library failed to init: instrument
  </code></pre>
  
  <p>Here is ObjectSizeTest's code:</p>
  
  <pre><code>public class ObjectSizeTest {
      public static void main(String[] args) {
          String s = new String("sai");
          System.out.println(ObjectSizeFetcher.getObjectSize(s));
      }
  }
  </code></pre>
  
  <p>MANIFEST.MF (for size.jar):</p>
  
  <pre><code>Manifest-Version: 1.0
  Created-By: 1.5.0_18 (Sun Microsystems Inc.)
  
  Premain-Class: ObjectSizeFetcher
  </code></pre>
  
  <p>and here is ObjectSizeFetcher's code:</p>
  
  <pre><code>import java.lang.instrument.Instrumentation;
  
  public class ObjectSizeFetcher {
      private static Instrumentation instrumentation;
  
      public static void premain(String args, Instrumentation inst) {
          instrumentation = inst;
      }
  
      public static long getObjectSize(Object o) {
          return instrumentation.getObjectSize(o);
      }
  }
  </code></pre>