Making a JAR with zip

M

mack

I want to make a JAR file programmatically from a native app (C++, not
Java), ultimately using zlib to create the jar.

As a test, I tried this:

I took a working JAR file, unzipped it, then rezipped it, and set the
extension to .jar. Running it tells me it could not find the manifest.

Unzipping the rezipped file looked exactly the same as the unzipped JAR
file, however.

I read somewhere (is it true?) that the manifest must be the first item in a
jar. So, I used the command line zip command to specify each file. It
reports that it "added" the files in the order I listed them. Unzipping the
result appeared to confirm that the manifest was indeed first. Renaming it
..jar and running it, again, tells me it could not find the manifest.

Why aren't my hand-made jar files working?
What is the difference between a jar and a zip file with a .jar extension?


Thanks.

Mack
 
L

Liz

mack said:
I want to make a JAR file programmatically from a native app (C++, not
Java), ultimately using zlib to create the jar.

As a test, I tried this:

I took a working JAR file, unzipped it, then rezipped it, and set the
extension to .jar. Running it tells me it could not find the manifest.

Unzipping the rezipped file looked exactly the same as the unzipped JAR
file, however.

I read somewhere (is it true?) that the manifest must be the first item in a
jar. So, I used the command line zip command to specify each file. It
reports that it "added" the files in the order I listed them. Unzipping the
result appeared to confirm that the manifest was indeed first. Renaming it
.jar and running it, again, tells me it could not find the manifest.

Why aren't my hand-made jar files working?
What is the difference between a jar and a zip file with a .jar extension?


Thanks.

Mack
I did something similar to try to reproduce your problem and it works for me
even though the jar and zip files are different sizes.

sitting in NewDraw\bin directory

jar cvfm NewDraw.jar META-INF/MANIFEST.MF *.class
mkdir save
cd save
unzip ..\NewDraw.jar
zip thing META-INF/MANIFEST.MF *.class
ren thing.zip NewDraw.jar
java -jar NewDraw.jar

application runs fine
 
T

Thomas Weidenfeller

mack said:
I read somewhere (is it true?) that the manifest must be the first item in a
jar.

Yes, it is. If you can bring yourself to have a look at the source of
the constructor of e.g. JarInputStream, you will see for yourself why.
So, I used the command line zip command to specify each file. It
reports that it "added" the files in the order I listed them. Unzipping the
result appeared to confirm that the manifest was indeed first. Renaming it
.jar and running it, again, tells me it could not find the manifest.

Why aren't my hand-made jar files working?

Who knows?

You did place the manifest in the right directory?

Did you make sure you used the proper file name case and directory name
case? Java is case sensitive, and Mainfest, mainfest and MANIFEST are
three different file names as far as Java is concerned.

Which compression algorithm did you use? Java jars only support deflate
(early Java version not even that).
What is the difference between a jar and a zip file with a .jar extension?

A jar file is a valid zip file, but not every zip file is a valid jar file.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,841
Latest member
WilmerBelg

Latest Threads

Top