import java.util.*;
public class checkVersion {
JarFile jarFile;
Manifest manifest;
Attributes attributes;
String jarFileName;
String version;
public checkVersion(String filename) {
jarFileName = filename;
}
public void printVersion() {
try {
// jar 파일을 읽습니다.
jarFile = new JarFile(new File(jarFileName));
// jar 파일에서 manifest 정보를 가져옵니다.
manifest = jarFile.getManifest();
// manifest에서 main 정보를 가져옵니다.
attributes = (Attributes)manifest.getMainAttributes();
// attribute 중에서 Implementation-Version 정보를 추출한다.
version = attributes.getValue("Implementation-Version");
System.out.println("@@ " + version);
/* 아래처럼 하면 manifest의 main 정보 전체를 확인할 수 있다.
for (Iterator it=attributes.keySet().iterator(); it.hasNext(); ) {
Attributes.Name attrName = (Attributes.Name)it.next();
String attrValue = attributes.getValue(attrName);
System.out.println("## " + attrName + " : " + attrValue);
}
*/
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
if( args.length != 1 ) {
System.out.println("Usage : ");
System.out.println(" java printVersion [jar_file_name]");
return;
}
/*
if( !(new File(args[0])).exists() ) {
System.out.println("Error : ");
System.out.println("[" + args[0] + "] file does not exist.");
return;
}
*/
checkVersion cv = new checkVersion(args[0]);
cv.printVersion();
}
}
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Niall Pemberton
Build-Jdk: 1.5.0_07
Bundle-License:
http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-ManifestVersion: 2
Bundle-Name: Apache Commons IO Bundle
Bundle-SymbolicName: org.apache.commons.io
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 1.4
Export-Package: org.apache.commons.io;version=1.4,
org.apache.commons.io.comparator;version=1.4,
org.apache.commons.io.filefilter;version=1.4,
org.apache.commons.io.input;version=1.4,
org.apache.commons.io.output;version=1.4
Implementation-Title: Commons IO
Implementation-Vendor: The Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.4
Import-Package: org.apache.commons.io;version=1.4,
org.apache.commons.io.comparator;version=1.4,
org.apache.commons.io.filefilter;version=1.4,
org.apache.commons.io.input;version=1.4,
org.apache.commons.io.output;version=1.4
Specification-Title: Commons IO
Specification-Vendor: The Apache Software Foundation
Specification-Version: 1.4
X-Compile-Source-JDK: 1.3
X-Compile-Target-JDK: 1.3
weblogic@WAS01[/export/home/weblogic]# java checkVersion commons-net-1.4.1.jar
@@ 1.4.1