我在罐子里有一个类的方法,我想用自己的身体交换它.在这种情况下,我只想让方法将"GOT IT"打印到控制台并返回true;
我正在使用系统加载器来加载jar的类.我使用反射使系统类加载器能够通过字节码加载类.这部分似乎工作正常.
我按照这里找到的方法替换示例:asm.ow2.org/current/asm-transformations.pdf.
我的代码如下:
public class Main
{
public static void main(String[] args)
{
URL[] url = new URL[1];
try
{
url[0] = new URL("file:////C://Users//emist//workspace//tmloader//bin//runtime//tmgames.jar");
verifyValidPath(url[0]);
}
catch (Exception ex)
{
System.out.println("URL error");
}
Loader l = new Loader();
l.loadobjection(url);
}
public static void verifyValidPath(URL url) throws FileNotFoundException
{
File filePath = new File(url.getFile());
if (!filePath.exists())
{
throw new FileNotFoundException(filePath.getPath());
}
}
}
class Loader
{
private static final Class[] parameters = new Class[] {URL.class};
public static void addURL(URL …Run Code Online (Sandbox Code Playgroud)