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
how to add files to jars META-INF
提问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-INF
directory among the .class-files that you want to be included in the jar. Put whatever you want in this META-INF
directory, 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 somefolder
under META-INF
:
以下是如何创建一个JAR使用自定义文件夹somefolder
下META-INF
:
mkdir META-INF
cp -a somefolder META-INF
jar cvf jarfile.jar META-INF/