[英]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.