Is it possible to move the .class files in a jar from the default package to another named package so that I can import and use them?
After browsing other questions here, I think jarjar might be exactly what im looking for, but I don't have any idea how I can use it.
So my question is how to use jarjar to repackage .class files from the default package to another named package?
EDIT: I want to clarify something - I do not have the sources of the jar I want to repackage, so I don't know how I could recompile the code. Obfuscation and reflection is out of the question.
EDIT2: It appears its extremely simple to do using jarjar :) java -jar jarjar.jar process rules.rules in.jar out.jar
rules.rules look something like this: rule a net.ylivay.src.a
Problem solved!
To move classes into a different package, you not only need to change their location in the jar (or filesystem) directory structure, you also need to change the package
declaration in the source files and then recompile the classes.
Instead of trying to repackage a jar, you should probably look at the powerful refactoring tools available in IDEs like Eclipse, which make this kind of thing simple. But since you say (in update to your question) that you don't have the source files, that is not possible.
The alternative would be to create proxy classes which invoke the ones you need in the default package using reflection. But not only is that unpleasant, but you say that reflection is out of the question.
So you cannot do what you want to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With