简体   繁体   English

提取和重新创建的jar不支持“ META-INF / MANIFEST.MF”中的清单。

[英]Extracted and recreated jar does not honor manifest at `META-INF/MANIFEST.MF`

I am trying to figure out how to package a Jython program as a standalone runnable jar and I have run into a strange problem. 我试图弄清楚如何将Jython程序打包为独立的可运行jar,但遇到了一个奇怪的问题。

mkdir /tmp/stackoverflow

Get the Jython standalone jar somehow. 以某种方式获取Jython独立jar。

wget http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar && mv ./*.jar ./jython-standalone-2.7.0.jar

Observe that it runs a Jython repl when not passed a script as a command line argument. 请注意,当未将脚本作为命令行参数传递时,它将运行Jython repl。

java -jar ./jython-standalone-2.7.0.jar

Produces: 产生:

Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_95
Type "help", "copyright", "credits" or "license" for more information.

When I unpack the jar and repack it, it complains about a missing manifest. 当我打开罐子并重新包装时,它抱怨缺少清单。

mkdir unpack
cd unpack
jar -xf ../jython-standalone-2.7.0.jar
# repack jar
jar -cvf output.jar ./*

This time java -jar output.jar produces the following output 这次java -jar output.jar产生以下输出

no main manifest attribute, in output.jar

As it turns out the contents of output.jar and jython-standalone-2.7.0.jar differ, but I think this this is just the nature of the beast when it comes to compression 事实证明, output.jarjython-standalone-2.7.0.jar有所不同,但是我认为这只是压缩过程中野兽的本质。

$ diff output.jar ../jython-standalone-2.7.0.jar
Binary files output.jar and ../jython-standalone-2.7.0.jar differ

The paths contained within do not differ, however (the following command produces no output) 但是,其中包含的路径没有不同(以下命令不产生任何输出)

$ diff <(jar -tf ../jython-standalone-2.7.0.jar | sort) <(jar -tf output.jar | sort)

What the heck is going on? 到底他妈发生了什么? Why isn't the new jar honoring the MANIFEST.MF it contains? 为什么新的jar不尊重其中包含的MANIFEST.MF

As it turns out, the jar needs to be explicitly told where to look for the MANIFEST.MF file. 事实证明,需要明确告知jar文件在哪里查找MANIFEST.MF文件。

jar -cvmf META-INF/MANIFEST.MF output.jar ./* 

produces a jar that can be run just like the original one. This still leaves the question of what file actually changes when a `MANIFEST.MF` file is specified as an argument.

Can't execute jar- file: "no main manifest attribute" 无法执行jar文件:“无主清单属性”

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

相关问题 META-INF / MANIFEST.MF文件中的库依赖关系 - library dependencies in META-INF/MANIFEST.MF file Aws Lambda访问META-INF / MANIFEST.MF? - Aws Lambda access to META-INF/MANIFEST.MF? 如何从* .war / META-INF / MANIFEST.MF文件中读取manifest.mf? - How to read manifest.mf from *.war/META-INF/MANIFEST.MF file? jar文件中缺少主要属性,MANIFEST.MF文件位于META-INF文件夹中 - Missing main attribute inside the jar file, the MANIFEST.MF file is located in META-INF folder 对于 JIMAGE 文件,什么相当于 JAR 文件 META-INF/MANIFEST.MF? - What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file? Java - 即使 MANIFEST.MF 文件位于 /META-INF 中,App.jar 中也没有主要清单属性 - Java - No Main Manifest Attribute, in App.jar error even though MANIFEST.MF file is in /META-INF 为什么喜欢/ WEB-INF / lib到/META-INF/MANIFEST.MF用于webapps? - Why prefer /WEB-INF/lib to /META-INF/MANIFEST.MF for webapps? 如何在Spring Boot应用程序中读取我的META-INF / MANIFEST.MF文件? - How to read my META-INF/MANIFEST.MF file in a Spring Boot app? 在unnamed.war中找不到META-INF / MANIFEST.MF文件 - META-INF/MANIFEST.MF file not found in unnamed.war 为什么不能使用maven-war-plugin将密钥与“ WEB-INF / classes / META-INF / MANIFEST.MF”合并? - Why keys are not merged with “WEB-INF/classes/META-INF/MANIFEST.MF” using maven-war-plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM