Question

I'm an experienced developer, but with very little Java experience. At my work, I've inherited a small JNLP project that needs to operate outside the sandbox (all-permissions). With JDK 1.7.0_51, I gather we now need to put "Permissions: all-permissions" in the manifest as well.

Up to now, we've been building it with DrJava, but in the DrJava menu Project | Create Jar File from Project, the checkbox for Custom Manifest is "grayed out" (unavailable). Consequently, I'm trying for the first time to build a JAR from the command line.

I've put the following in a file called 'manifest.txt':

Permissions: all-permissions
Main-class: main

(I believe that Main-class: main is needed, and that DrJava has up to now been doing that implicitly for me.) And, yes, I do have a newline after the last line.

When I try to build the JAR with a command line along the lines of...

jar -cvfm foo.jar manifest.txt main.class UUID.class etc.class

... I get the following exception:

java.io.IOException: invalid header field
    at java.util.jar.Attributes.read(Attributes.java:389)
    at java.util.jar.Manifest.read(Manifest.java:182)
    at java.util.jar.Manifest.<init>(Manifest.java:52)
    at sun.tools.jar.Main.run(Main.java:151)
    at sun.tools.jar.Main.main(Main.java:1149)

I'm running on Microsoft Windows 7, for what little that may be worth. Also, for what it's worth, I've seen examples online with both 'cvfm' and '-cvfm'. I've tried both, it doesn't seem to matter.

I presume the problem is in my manifest.txt, and I've read http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html, but I don't see what I might be doing wrong.

I'd be perfectly happy with either a DrJava solution or a command-line solution.

Was it helpful?

Solution

Got it. It turns out that when you install JDK 1.7.0_51 (or at least when I did) it doesn't update the system path. You have to hand-edit that. So I was really running the JDK 1.6.1_25 JAR rather than the 1.7.0_51, and I'd guess "Permissions" in the manifest is not known to JDK 1.6.1_25. Not the clearest error message, and googling did not lead to an answer. I hope this will be of help to someone else: if "Permissions" is in your manifest, then “invalid header field” may mean your path is pointing to too old a version of the JDK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top