6

Java替换jar包中的文件

 10 months ago
source link: https://itlanyan.com/java-update-jar-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java替换jar包中的文件

Javatlanyan

帮朋友一个小忙,因此研究了一下 Java 怎样替换jar包中的文件。

操作步骤如下:

1. 安装 Java 开发工具包,可从 OpenLogic网站下载:https://www.openlogic.com/openjdk-downloads,也可通过包管理器等工具安装;

2. 解压jar包:jar xf xxx.jar,该命令也可以解压war包;

3. 对于class文件,需要用 jadx 等 java反编译工具 提取出源码,然后用 intelliJ IDEA 等工具修改,编译成新的class文件;对于文本、图片等资源文件,请自行替换修改;

4. 替换文件: jar uf xxx.jar com/xxx/x.class,注意这里 com/xxx/xxx.class 的路径需和jar中的路径完全一致!

5. 用新的jar包替换原来的。

不知为何,用 jar cf0m 方式重新打包会报找不到类的错误,没去深究。

1. Java 命令方式添加,替换jar包中class文件


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK