【问题标题】:java instrumentation jar in eclipse - failure in manifest.mfeclipse 中的 java 仪表 jar - manifest.mf 中的失败
【发布时间】:2011-06-08 08:23:44
【问题描述】:

我正在尝试使用需要使用“premain”类的 java.lang.instrument.Instrumentation 类 - 可以在 stack here 上找到一个很好的描述。

问题是我已经这样做了,但在另一个程序中使用它时遇到了问题。我的班级是这样的:

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;
  }
}

清单在 Jar 文件中,如下所示:

$ 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

而 MANIFEST.MF 只是:

$ more src/resources/META-INF/MANIFEST.MF

Manifest-Version: 1.0

Premain-Class: com.testTools.instrumentation.InstrumentationWrapper

在 eclipse 的启动配置中出现以下问题

Z:\workspace\&lt;project&gt;\testTools\instrumentor\target\instrumentator-1.0.jar 中找不到 Premain-Class 清单属性

选项是-javaagent:${workspace_loc:instrumentator}\target\instrumentator-1.0.jar

我真的不确定如何让它工作 - 我真正需要做的就是拥有一个测试工具,它可以让我查看数组的内存足迹。有什么想法吗?

【问题讨论】:

    标签: java jar manifest instrumentation


    【解决方案1】:

    什么都没有,但如果你想进一步检查,你可以编写一个快速类来打开你的 Jar 文件 java.util.jar.JarFile 并以编程方式检查清单。这将表明问题是否出在您编写清单的方式(可能是错误位置的空格或其他什么)或它的加载方式(可能在 premain 类的规范中有错字?)。

    【讨论】:

      猜你喜欢
      • 2015-12-31
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 2011-05-18
      • 2011-09-10
      • 1970-01-01
      • 2018-11-01
      • 2011-03-04
      相关资源
      最近更新 更多