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

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

问题描述

如何从 jar 文件中读取(加载)java 类,向类中添加一些代码,然后放回 jar 中?我需要编写一个脚本(一个 java 代码)来完成所有这些事情.我想到的步骤是:1. 读取jar,使用java.util.jar包中的方法获取类名的条目2.加载这个类,从类中获取数组,改变它3. 也许编译代码以应用更改4.将更新后的class放入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?

推荐答案

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

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

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

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