“无法加载Premain-Class清单属性”同时尝试使用java代理获取对象的大小 [英] "Failed to load Premain-Class manifest attribute" while trying to get the size of an object using java agent
问题描述
当我尝试运行java程序( java -javaagent:size.jar ObjectSizeTest
)时,我收到以下错误:
When i try to run a java program (java -javaagent:size.jar ObjectSizeTest
) i get the following error:
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
这是ObjectSizeTest的代码:
Here is ObjectSizeTest's code:
public class ObjectSizeTest {
public static void main(String[] args) {
String s = new String("sai");
System.out.println(ObjectSizeFetcher.getObjectSize(s));
}
}
MANIFEST.MF(适用于size.jar):
MANIFEST.MF (for size.jar):
Manifest-Version: 1.0
Created-By: 1.5.0_18 (Sun Microsystems Inc.)
Premain-Class: ObjectSizeFetcher
这里是ObjectSizeFetcher的代码:
and here is ObjectSizeFetcher's 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);
}
}
推荐答案
制作确定你已经给出了包含pre-main方法的类的完整java路径。
例如像org.eclipse.anotherpckg.ObjectSizeFetcher。其次,名称和运输结束前必须有一个空格。例如
Make sure you have give full java path of the class containing the pre-main method. for example like this org.eclipse.anotherpckg.ObjectSizeFetcher. Secondly there must be a space before the name and carriage return at the end. for example
Manifest-Version: 1.0
Created-By: 1.5.0_18 (Sun Microsystems Inc.)
Premain-Class: org.eclipse.package.ObjectSizeFetcher
最后一行是由于回车。
这篇关于“无法加载Premain-Class清单属性”同时尝试使用java代理获取对象的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!