java 如何将文件添加到 jars META-INF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4079675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:41:24  来源:igfitidea点击:

how to add files to jars META-INF

javajar

提问by evan

i want to create a jar file in which i want to place some file in the META-INF folder of the jar file.is it possible ? .i know how to create a jar file but clueless about how to put files inside META-INF

我想创建一个 jar 文件,我想在其中放置一些文件在 jar 文件的 META-INF 文件夹中。这可能吗?.我知道如何创建一个 jar 文件,但对如何将文件放入 META-INF 一无所知

below is my desired jar files META-INF directory

下面是我想要的 jar 文件 META-INF 目录

META-INF > somefolder > somefile

META-INF > somefolder > somefile

回答by dogbane

jar uf jarfile.jar META-INF/somefolder/somefile

回答by thejh

Rename the .jar-file to something ending with .zip, open it with an appropriate program, change what you want to change, save it and rename it back to .jar. Jarfiles are Zipfiles.

.jar-file.zip重命名为以.jar. Jarfile 是 Zipfile。

回答by Jeff Swensen

From the jar documentation:

jar 文档

Updates an existing file jarfile (when f is specified) by adding to it files and directories specified by inputfiles. For example: jar uf foo.jar foo.class

通过将 inputfiles 指定的文件和目录添加到现有文件 jarfile(当指定 f 时)来更新它。例如:jar uf foo.jar foo.class

回答by Roman Goyenko

You probably have the META-INF folder already when you create the jar from the source. Just put your files there before making the jar.

当您从源代码创建 jar 时,您可能已经有了 META-INF 文件夹。在制作 jar 之前,只需将您的文件放在那里。

回答by aioobe

Try creating a META-INFdirectory among the .class-files that you want to be included in the jar. Put whatever you want in this META-INFdirectory, and it will be included in the compiled jar-file.

尝试META-INF在要包含在 jar 中的 .class 文件中创建一个目录。把你想要的任何东西放在这个META-INF目录中,它将被包含在编译的 jar 文件中。

回答by mrts

Here's how to create a JAR with a custom folder somefolderunder META-INF:

以下是如何创建一个JAR使用自定义文件夹somefolderMETA-INF

mkdir META-INF
cp -a somefolder META-INF
jar cvf jarfile.jar META-INF/