如何将 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" );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)