[Development tips] modify the jar package again

Source: Internet
Author: User

Fan Huan is a java enthusiast.
Email: heydaymail@hotmail.com
Blog: http://heyday.blogone.net
2005-6-19

Introduction
In learning and developing JAVA projects, we often use some third-party jar files. Using these third-party Toolkit can improve our development efficiency and shorten the development time. Some third-party tools provide detailed instructions and source code, but sometimes some do not provide the source code, and the instructions are not very detailed, which is very inconvenient for us to use.
If you know it, you know it. Sometimes, we must read the packaged classes in jar. Sometimes it is possible to make small changes to make it suitable for your special needs.

Preparations
Java decompilation tool:
It is strongly recommended that Xiaoying JAVA source code decompilation Expert series 1.4 release version.
Compression tool:
Winrar

(These tools can be found on the network by searching)

Start
1. decompress the jar package
We can use the winrar tool to decompress the jar to the specified directory.

2. decompilation class
Use the Java decompilation tool to decompile the class file into a java file. (Most decompilation tools only provide the decompilation of a single class file. We recommend the "JAVA source code decompilation" tool to decompile all class files in a directory)

3. Build a project
We set the decompiled java file to the project's source file directory.
Add jar and other lib required by jar to the project as libraries to ensure that our java files can be compiled.

4. Modify the decompiled java
The decompiled java file may have errors and cannot be compiled. without affecting the author's original intention, we must make small changes to it to ensure that it can be compiled.

Make sure that the java file can be compiled and modified based on it to meet your needs.

5. Compile the modified java
Compile the modified java file. Note that it is best to compile only a modified java file.
After the compilation is complete, we test to ensure that the modification is correct. The JVM will first find the class file under the classes directory and add it first. In this way, we modify the compiled class file, which is the class file used for testing.
Repeat this process until java achieves our goal.

6. Jar package
Replace the generated class file with the corresponding class file under the decompressed jar directory, and then package it again to generate the jar.
We can use the jar command for packaging, or the winrar tool for packaging. When using the winrar tool for packaging, be sure to select the compressed file format as zip and set the extension name of the generated compressed file to jar.

Replace the original jar. Perform the last test again.

Summary
Because of the cross-platform nature of Java, the java class file can be decompiled. We can modify the jar file to suit our own needs.
To modify the jar file, we must first obtain the consent of the jar developer.

To modify the jar file, you must first be familiar with the decompiled java file. This requires good code reading capability, clear the author's technical architecture and development and design ideas. If you are unsure, it is best to contact the jar developer to raise your requirements.

For some java developers, they do not want to publish their hard-coded code to the public. To avoid others' decompilation, they can use obfuscators, but they only increase the difficulty of code reading. If it is not for commercial use, we still hope that developers can provide source code and learn from each other.

About the author
Fan Huan java lovers, you can contact me through heydaymail@hotmail.com.
Email: heydaymail@hotmail.com
Blog: http://heyday.blogone.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.