Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hand Edit A Jar to Change Package Names

Tags:

java

maven

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 
like image 542
Ben Noland Avatar asked Dec 06 '12 15:12

Ben Noland


People also ask

Can you rename packages in Java?

Right-click the package you want to move, and select " Refactor/Rename..." -- NOT " Move "! Modify the name of the package to reflect its desired new position in the package hierarchy, e.g.


Video Answer


1 Answers

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.)

like image 191
Maik Schreiber Avatar answered Sep 19 '22 21:09

Maik Schreiber