Javassist using a jar file

丶灬走出姿态 提交于 2019-12-24 11:12:05

问题


How do I add a jar file to the search path for javassist and have it work correctly? I am trying to modify a jar file without unjaring then rejaring.

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:


Solved it simply:

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


来源:https://stackoverflow.com/questions/16745206/javassist-using-a-jar-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!