title: java instrumentation jar in eclipse - failure in manifest.mf
body: <p>I am trying to use the java.lang.instrument.Instrumentation class which requires usage of the 'premain' class - a good descrip can be found on <a href="https://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object">stack here</a>.</p>
  
  <p>The problem is that I have done this and am having trouble using it in another program. My class looks like this:</p>
  
  <pre><code>public class InstrumentationWrapper {
    private static final String INSTR_KEY = "test.instrumentation";
    private static Instrumentation instrumentation;
  
    public static void premain(String options, Instrumentation inst) {
      Properties props = System.getProperties();
      if(props.get(INSTR_KEY) == null)
        props.put(INSTR_KEY, inst);
    }
  
    public static Instrumentation getInstrumentation() { 
      if (instrumentation == null) {
        instrumentation = (Instrumentation) System.getProperties().get(INSTR_KEY); 
      }
  
      return instrumentation;
    }
  
    public static long getObjectSize(Object o) {
        return instrumentation.getObjectSize(o);
    }
  
    public static long getSizeOfObjects (Collection&lt;?&gt; col) {
      long cumSize = 0;
  
      for (Object o : col) {
        cumSize = getObjectSize (o);
      }
  
      return cumSize;
    }
  }
  </code></pre>
  
  <p>The manifest is in the Jar file as such: </p>
  
  <pre><code>$ jar -tf target/instrumentator-1.0.jar
  META-INF/
  META-INF/MANIFEST.MF
  com/
  com/testTools/
  com/testTools/instrumentation/
  com/testTools/instrumentation/InstrumentationWrapper.class
  META-INF/maven/
  META-INF/maven/com.netrecon.testTools/
  META-INF/maven/com.netrecon.testTools/instrumentator/
  META-INF/maven/com.netrecon.testTools/instrumentator/pom.xml
  META-INF/maven/com.netrecon.testTools/instrumentator/pom.properties
  </code></pre>
  
  <p>and the MANIFEST.MF is just:</p>
  
  <pre><code>$ more src/resources/META-INF/MANIFEST.MF
  
  Manifest-Version: 1.0
  
  Premain-Class: com.testTools.instrumentation.InstrumentationWrapper
  </code></pre>
  
  <p>In the launch configuration in eclipse I get the following problem </p>
  
  <p>Failed to find Premain-Class manifest attribute in <code>Z:\workspace\&lt;project&gt;\testTools\instrumentor\target\instrumentator-1.0.jar</code></p>
  
  <p>and the option is <code>-javaagent:${workspace_loc:instrumentator}\target\instrumentator-1.0.jar</code></p>
  
  <p>I am really unsure how I can get this to work - All I really need to do is have a test harness that will let me look at the memory foot print of an array. Any ideas?</p>