मैं जावा एजेंटों पर नौसिखिया हूं। मैं एक साधारण HotswapAgent श्रेणी का निर्माण (Play से सूँघने फ्रेमवर्क!):जावागेंट रिपोर्ट "redefineClasses इस वातावरण में समर्थित नहीं है"
public class HotswapAgent {
static Instrumentation instrumentation;
public static boolean enabled = false;
public static void premain(String agentArgs, Instrumentation instrumentation)
{
HotswapAgent.instrumentation = instrumentation;
HotswapAgent.enabled = true;
}
public static void reload(ClassDefinition... definitions)
throws UnmodifiableClassException, ClassNotFoundException
{
instrumentation.redefineClasses(definitions);
}
}
इस प्रकट साथ:
Manifest-Version: 1.0
Premain-Class: path.to.HotswapAgent
Can-Redefine-Classes: true
और मैं एक नया वर्ग परिभाषा को फिर से लोड करने के लिए, इस तरह से प्रयास करें:
CtClass modelClass = ....
...
byte [] bcode = modelClass.toBytecode();
Class c = modelClass.toClass();
modelClass.defrost();
ClassDefinition cdef = new ClassDefinition(c, bcode);
HotswapAgent.reload(cdef);
ये सभी कक्षाएं एक जार में हैं, और अंततः मुझे यह त्रुटि (पुनः लोड() कॉल पर) प्राप्त होती है:
redefineClasses is not supported in this environment
लेकिन मेनिफेस्ट में Can-Redefine-Classes: true
घोषित किया गया है।
जेवीएम मानक मैकोज़ एक्स जावा 1.6 वीएम है। यह जेवीएम जेआरबेल के साथ अच्छा काम करता है, जो एक ही एजेंट तंत्र का उपयोग करता है।
क्या गलत है?