简体   繁体   中英

copy contents jar file from another jar file

Is it possible to copy the contents of one jar file to another jar file? I'm talking about creating a clean archive here. In the previous jar file, the file data is still intact (I can access it using a archive utility, such as Winrar, but the JDK/JRE fails to load it, for some reason or other)

I'm having difficulty unpacking the entire JAR because my OS treats some files case in sensitive and those will get trashed upon extraction.

So I need to do it in memory or have some other case-sensitive file or archive system such as rar, tar, 7z or gunzip. It would be good if there is such off the shelf code, but don't mind if I can do it grammatically as well.

The Java 7 NIO.2 API (java.nio.file) can easily accomplish this. It can treat the jar file (which is really just a .zip file) as a filesystem in its own right, and copy files directly from it.

Take a look at the javadoc for java.nio.file.Path and java.nio.file.Files, and then look for a cookbook recipe based on those classes.

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