[英]Javassist using a jar file
如何将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 );
}
}
简单地解决了它:
pool.insertClassPath( "/Path/from/root/myjarfile.jar" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.