开发者

java instrumentation jar in eclipse - failure in manifest.mf

I am trying to use the java.lang.instrument.Instrumentation cl开发者_开发问答ass 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?


Nothing jumps out at me, but if you want to inspect further you can write a quick class to open up your Jar file with java.util.jar.JarFile and programatically inspect the manifest. This will indicate whether the issue is somehow in the way you wrote your manifest (maybe a space in the wrong place or something) or the way it's getting loaded (Maybe there is a typo in the specification of the premain class?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜