简体   繁体   中英

Javassist using a jar file

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 );


  }
}

简单地解决了它:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM