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 stack here.
The problem is that I have done this and am having trouble using it in another program. My class looks like this:
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<?> col) {
    long cumSize = 0;
    for (Object o : col) {
      cumSize = getObjectSize (o);
    }
    return cumSize;
  }
}
The manifest is in the Jar file as such:
$ 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
and the MANIFEST.MF is just:
$ more src/resources/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Premain-Class: com.testTools.instrumentation.InstrumentationWrapper
In the launch configuration in eclipse I get the following problem
Failed to find Premain-Class manifest attribute in Z:\workspace\<project>\testTools\instrumentor\target\instrumentator-1.0.jar
and the option is -javaagent:${workspace_loc:instrumentator}\target\instrumentator-1.0.jar
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?
 
     
    