问题
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
Then to inject the manifest into my jar
- I save the manifest.txt file in the same directory as the jar
- then in mac osx terminal I type: `jar cfm MyGreat.jar manifest.txt
As a result, I get the following error
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?
Another approach might be to recreate the jar anew. So I did the following
- 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.
So maybe someone can tell me how to create a jar with manifest from terminal. I know the command: jar cvf MyGreat.jar MyGreat
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
回答1:
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
Note the additional space after the Application-Library-Allowable-Codebase: and Caller-Allowable-Codebase: entry.
According to the jar file specification, value is defined as:
value: SPACE *otherchar newline *continuation
If you add the spaces, it works as expected.
来源:https://stackoverflow.com/questions/21411834/how-do-i-inject-new-manifest-into-an-existing-jar-for-applet