简体   繁体   中英

creating patch from code or existing jar / classes

Requirement:
To create a patch (with required classes alone)

I tried like this:

  • Generated a jar using maven.
  • Copied few class files manually to path/to/files folder
  • Then created a new jar file using command jar cvf patch.jar -C path/to/files

When I decompile the class files via Intellij from the first jar's class files, I could see the correct code more or less. But when I check from the second jar file the code is different.

Is it because in the second jar it is being compiled into byte format again? If so are there any consequence of this? The reason why I create a second jar is because I only need those specific class files in the folder as we use it as a patch.

Or is there any way to create a patch?

Here's my suggestion.

  • Do not create a jar from another class files / jar.
  • Do create a new jar with your required class using maven itself.

How?

  • Create a copy of your project folder
  • Rename the artifact as patch-of-your-project-name
  • Now remove unwanted classes (or say, keep your required files alone)
  • Do maven build to create Jar (the new jar name will be patch-of-...

This way, build errors can be noted/logged easily and you can also automate the process by providing the required files list to a script and then do the maven build.

Note: There's a maven plugin maven-patch-plugin . Please check if you can make use of it.
https://maven.apache.org/plugins/maven-patch-plugin/


Remove from the jar A jar is just a zip file after all. Remove a single file from existing jar. Definitely much faster than uncompressing/recompressing too.

zip -d file.jar unwanted_file.txt

Add to the jar Add class to a new jar

jar uf C:\folder\where\jar\is\the_jar_file.jar file.class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM