First of all we have to say why to modify the jar file package name, jar package we will be very high frequency use, especially with some other three-party library, often the Java code into a jar file, easy to use the project dependencies. The author encountered some problems in the development process, because the jar file inside the package name and the project or runtime Environment reference file package name conflict caused, this time we modify the jar file package name is a relatively fast and effective solution. Give two examples, the author personally experienced two situations.
- Gson Library: This is believed to be used by a lot of people, but directly into the Gson jar package, the HTC Desire HD This phone will throw an exception (typenotfoundexception)
- Jackson Library: This is also a JSON parsing, we are doing apple push back-end, the background with Java write, use Java-apns library, rely on Jackson, and then run will throw exception, the specific reason is not checked, the initial suspicion of the package name conflict, modified after the solution.
Here's how to modify the package name of a jar file, which requires a gadget called Jarjar.jar
- : http://code.google.com/p/jarjar/downloads/list
Here we take Gson.jar as an example, in the Gson.jar package directory to create a new text file, the name is arbitrary, such as Rule.txt, write the following content.
Rule com.google.gson.** [email protected]
It is written to modify the rules, and we will modify the Gson in the package name to Mygson. Open the command line and enter the following command.
Java-jar Jarjar.jar process Rule.txt Gson.jar Mygson.jar
command execution, the same directory will be more Mygson.jar, this is the change package name after the jar file, our project import this jar package to use.
How to modify the package name of a jar file under Android programming