简体   繁体   English

从另一个jar文件复制内容jar文件

[英]copy contents jar file from another jar file

Is it possible to copy the contents of one jar file to another jar file? 是否可以将一个jar文件的内容复制到另一个jar文件? 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) 在先前的jar文件中,文件数据仍然完整(我可以使用诸如Winrar之类的存档实用程序来访问它,但是JDK / JRE出于某种原因无法加载它)

I'm having difficulty unpacking the entire JAR because my OS treats some files case in sensitive and those will get trashed upon extraction. 我在解压整个JAR时遇到了困难,因为我的操作系统将某些文件区分为敏感文件,并且这些文件在提取时会被丢弃。

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. 因此,我需要在内存中执行此操作,或者需要使用其他区分大小写的文件或归档系统,例如rar,tar,7z或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. Java 7 NIO.2 API(java.nio.file)可以轻松实现此目的。 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. 它可以将jar文件(实际上只是一个.zip文件)视为文件系统,并直接从中复制文件。

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. 查看java.nio.file.Path和java.nio.file.Files的javadoc,然后根据这些类查找食谱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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