从jar文件更改类的代码 [英] Changing the code of the class from jar file

查看:129
本文介绍了从jar文件更改类的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从jar文件中读取(加载)java类,向类中添加一些代码然后放回到jar中?
我需要编写一个执行所有这些操作的脚本(java代码)。我想到的步骤是:
1.使用java.util.jar包中的方法读取jar并获取类名为class的条目
2.加载此类,从类中获取数组,更改它
3.也许编译代码以应用更改
4.将更新的类放到jar文件中

How can I read (load) the java class from jar file, add some code to the class and then put back to the jar? I need to write a script (a java code) which does all these things. Steps I think of are: 1. Read the jar and get the entry with the name of class by using methods from java.util.jar package 2. Load this class, get the array from the class, change it 3. Maybe compile the code to apply the changes 4. Put the renewed class to the jar file

我不知道如何在java中做第2步和第3步。

I dont know how to do 2nd and 3rd steps in java.

我正在考虑编写新的java类来扩展这个类并更改数组,但是这个数组被声明为public static final,这就是为什么我无法改变它。或者我错了,有一种方法可以通过扩展类来更改数组?

I was thinking to write new java class which extends this class and change the array, but this array is declared as public static final, thats why I cannot change it. Or I am wrong and there is a way of changing the array by extending the class?

推荐答案

提取 - > 反编译 - >添加代码 - >创建Jar

Extract -> Decompile -> Add code -> Create Jar

这篇关于从jar文件更改类的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆