2023-09-13, Wednesday, Cloudy

新工上遇上了挫折。寫好的東西達不到標準需要別人執手尾了。雖然同事說沒關係,但反應了自己的不足。有時反省自己為何做事總是不好,為何別人有留意或想到的事情自己總是忽略。現在覺得是自己天生的思考模式問題,可能看多少書都沒用。或者自己應該更適合做地盤呢類工作,而唔係IT。

no main manifest attribute in jar file

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

Popular posts from this blog

Install Apache Superset on Ubuntu 18.04

生的感覺、死的感覺

2023-03-18, Saturday, Sunny