Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

java - Hand Edit A Jar to Change Package Names

I have a jar file from an external source. All of the classes in the jar are in the com.xyz package.

I would like to move all of classes to the com.xyzold package.

Is this is simple as unzipping the jar, renaming the xzy folder to xyzold, and rezipping it, or do I need to modify each class file as well?


Here's my solution, using Jar Jar Links

java -jar jarjar-1.4.jar process rules.txt google-collections-1.0.jar google-collections-old-1.0.jar

And here's the contents of my rules.txt file:

rule com.google.** com.googleold.@1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Jar Jar Links to achieve that. Also you don't need the source code of the classes you'd like to modify, as the program does it on the bytecode level (ie. it modifies the .class files directly.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...