Javassist使用jar文件

时间:2013-05-25 00:14:42

标签: java javassist

如何将jar文件添加到javassist的搜索路径并使其正常工作?我试图修改一个jar文件,而不是疏忽然后再调整。

import javassist.*;

class Injector
{

  public static void main(String[] argv) throws Exception
  {
    // Load the class representation
    ClassPool pool = ClassPool.getDefault();
    pool.insertClassPath( "myjarfile.jar" ); 
    CtClass cc = pool.get("org.mine.Myclass"); ////////// Not reading Myclass from myjarfile.jar


    // Find the method we want to patch and rename it 
    // (we will be creating a new method with the original name).
    CtMethod m_old = cc.getDeclaredMethod("methodToRename");
    // m_old.setName( "methodToRename" );

    cc.removeMethod( m_old );


  }
}

1 个答案:

答案 0 :(得分:5)

简单地解决了:

pool.insertClassPath( "/Path/from/root/myjarfile.jar" );