2012-10-11 10 views
6

मैं जावा एजेंटों पर नौसिखिया हूं। मैं एक साधारण 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 वीएम है। यह जेवीएम जेआरबेल के साथ अच्छा काम करता है, जो एक ही एजेंट तंत्र का उपयोग करता है।

क्या गलत है?

उत्तर

2

documentation के अनुसार:

Optional Functionality: might not be implemented for all virtual machines. The following capability (as returned by GetCapabilities) must be true to use this function. 

आप अगर वहाँ प्रकट घोषणा के साथ एक समस्या है की जाँच करने के addCapability करने की कोशिश कर सकते हैं।

यहां एक example of addCapability in runtime है।

संबंधित मुद्दे