[英]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.jar
和jython-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.