Recently I need to create a jar with ant so after a few search I found that I have to work with a manifest file. Everything seems fine and I can build my jar file with ant happily until I use the ant's manifest task to add manifest file into jar file and run with "java -jar xxx.jar", I always get an error:
no main manifest attribute in xxx.jar
I was wondering why it doesn't work after I have follow the instructions
here and using the examples there as reference.
After started things all over again with basic Java tutorial on Oracle's website, finally I figure it out. It was all about the manifest file the ant task genereted:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.7
Created-By: 1.8.0_91-b14 (Oracle Corporation)
Built-By: Whelan Chan
Name: common
Main-Class: xxx.xxx.util.xxxRunner
There are two EOL after the "Built-By" attribute and so all the attributes after it could not be recognized. After I removed the extra EOL:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.7
Created-By: 1.8.0_91-b14 (Oracle Corporation)
Built-By: Whelan Chan
Name: common
Main-Class: xxx.xxx.util.xxxRunner
It works like a charm. And I get back to my build.xml file and found that removing
tags will do the trick and allow ant generating correct manifest file as above.
Well... it seems that the Main-Class attribute shall not be included in section. Finally in the
documentation of the Jar file, I found that the Main-Class attribute shall be include in the main section of the manifest file, including it in other section is a mistake and will bring you into a mess.
Comments