如何将新清单注入小程序的现有 jar 中 [英] How do I inject new manifest into an existing jar for applet
问题描述
我有一个已经运行多年的网站 (2).但是由于新的 Java 限制(2014 年 1 月),我的小程序被阻止了.所以在做了一些阅读之后,似乎我所要做的就是更改清单文件;我什至不需要重新编译代码.(如果我错了,请纠正我.)
I have a website that has been working for years (2). But since the new java restrictions (January 2014), my applet is blocked. So after doing some reading, it seems all I have to do is change the manifest file; I don't even need to recompile the code. (If I am wrong about this, please correct me.)
所以我创建了以下清单文件
So I have created the following manifest file
Manifest-Version: 1.0
Created-By: 1.7.0_51
Permissions: sandbox
Application-Name: MyFarmingBusiness
Application-Library-Allowable-Codebase:http://mycompany.com/version_4/myapplet/
Caller-Allowable-Codebase:www.mycompany.com
Codebase: www.mycompany.com
然后将清单注入到我的 jar 中
Then to inject the manifest into my jar
- 我将 manifest.txt 文件保存在与 jar 相同的目录中
- 然后在 mac osx 终端中输入:`jar cfm MyGreat.jar manifest.txt
结果,我收到以下错误
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:410)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:172)
at sun.tools.jar.Main.main(Main.java:1177)
有人知道如何解决这个问题吗?
Does anyone know how to fix this?
另一种方法可能是重新创建 jar.所以我做了以下
Another approach might be to recreate the jar anew. So I did the following
- 提取源码:
jar xf MyGreat.jar
- 但是,我已经很久没有这样做了,我不知道如何从源代码重建 jar:源代码仅包含
.class
目录中的com 文件/mycompany/...
和名为META-INF
的目录中的清单.我尝试在线搜索,但我对如何从终端执行此操作没有多少运气.
- to extract the source:
jar xf MyGreat.jar
- but then, I haven't done this in so long, I don't know how to reconstruct the jar from the source: the source only contains
.class
files in directorycom/mycompany/...
and the manifest in a directory calledMETA-INF
. I try searching online, but I haven't had much luck on how to do this from terminal.
所以也许有人可以告诉我如何从终端创建一个带有清单的 jar.我知道命令:jar cvf MyGreat.jar MyGreat
So maybe someone can tell me how to create a jar with manifest from terminal. I know the command: jar cvf MyGreat.jar MyGreat
但是我如何获取清单?我将与 .class
文件相关的清单放在哪里,这样最后我会得到一个包含目录的 jar 文件:com
和 META-INF代码>
But how do I get the manifest in? where to I put the manifest with respect to the .class
files so that in the end, I get a jar file with directories: com
and META-INF
推荐答案
冒号后缺少 空格.这应该有效:
You are missing a space after the colon. This should work:
Manifest-Version: 1.0
Created-By: 1.7.0_51
Permissions: sandbox
Application-Name: MyFarmingBusiness
Application-Library-Allowable-Codebase: http://mycompany.com/version_4/myapplet/
Caller-Allowable-Codebase: www.mycompany.com
Codebase: www.mycompany.com
注意 Application-Library-Allowable-Codebase: 和 Caller-Allowable-Codebase: 条目之后的额外 空格.
Note the additional space after the Application-Library-Allowable-Codebase: and Caller-Allowable-Codebase: entry.
根据 jar 文件规范、值定义为:
值:空格 *otherchar 换行符 *continuation
value: SPACE *otherchar newline *continuation
如果添加空格,它会按预期工作.
If you add the spaces, it works as expected.
这篇关于如何将新清单注入小程序的现有 jar 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!