今天有人問到 META-INF文件夾是干啥的,META-INF文件夾的作用, META-INF文件夾能刪嗎,還有項目的META-INF下面一般會有個MANIFEST.MF 文件,都是干啥的。
百度搜了一下,基本找不到答案。於是上stakoverflow搜,得到如下答案:
If you remove META-INF from a jar then there is no MANIFEST.MF and so java -jar can't find the main class.
You can create jars without META-INF but when you are going to execute a jar a META-INF/MANIFEST.MF is required.
See http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html
這句英文很簡單,簡單翻譯如下:
如果你將Jar中的META-INF文件夾刪除,那么jar文件里邊就沒有MANIFEST.MF文件。那么,java -jar就找不到main class.
沒有META-INF你仍然可以創建一個Jar文件。但是,當你想要執行jar文件的時候,這個jar是需要具備 META-INF/MANIFEST.MF的。
我們在使用eclipse或者myeclipse新建項目之后,在項目中可以找到META-INF文件夾,下面有個MANIFEST.MF。
打開之后發現里邊只有:
Manifest-Version: 1.0 Class-Path:
瞬間變有疑問:這么少點信息,有啥作用。為啥上面那段英文說的這個文件這么的不可或缺。
於是我隨便在項目的lib中找了一個jar文件commons-io-2.3.jar,打開,把里邊的MANIFEST.MF文件拿出來,打開如下:
Manifest-Version: 1.0 Export-Package: org.apache.commons.io.output;version="2.3",org.apache. commons.io.monitor;version="2.3",org.apache.commons.io.filefilter;ver sion="2.3",org.apache.commons.io.comparator;version="2.3",org.apache. commons.io.input;version="2.3",org.apache.commons.io;version="2.3" Implementation-Title: Commons IO Built-By: ggregory Tool: Bnd-1.50.0 Implementation-Vendor: The Apache Software Foundation Implementation-Vendor-Id: org.apache Specification-Title: Commons IO Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-SymbolicName: org.apache.commons.io X-Compile-Target-JDK: 1.6 Implementation-Version: 2.3 Specification-Vendor: The Apache Software Foundation Bundle-Name: Commons IO Created-By: Apache Maven Bundle Plugin X-Compile-Source-JDK: 1.6 Bundle-Vendor: The Apache Software Foundation Build-Jdk: 1.6.0_31 Bundle-Version: 2.3.0 Bnd-LastModified: 1334069963279 Bundle-ManifestVersion: 2 Bundle-Description: The Commons IO library contains utility classes, s tream implementations, file filters, file comparators, endian transfo rmation classes, and much more. Bundle-DocURL: http://commons.apache.org/io/ Implementation-Build: tags/2.3-RC1@r1311772; 2012-04-10 10:59:15-0400 Specification-Version: 2.3 Include-Resource: META-INF/LICENSE.txt=LICENSE.txt,META-INF/NOTICE.txt =NOTICE.txt Archiver-Version: Plexus Archiver
密密麻麻一大片,是一行行的,類似配置文件,前面一個'key' 后面一個‘value’
具體這些玩意有啥用,META-INF 里邊還可以放啥,可擊上面文字中提供的的連接。好長一片英文,感興趣的話,慢慢看吧。