好久沒玩這個了!復習一下!
D盤根目錄下寫 Test.java

public class Test
{

public static void main(String[] args)
{
System.out.println("*******--TEST JAVA!--*********");
}
}
javac Test.java
試一下 java Test OK!
jar cvf test1.jar Test.class,回車后去D盤,OK多了 test1.jar
jar cvf jar文件名 mf 文件名 .class文件
第二種玩法 做一個*.mf文件內容如下:
Manifest-Version: 1.0
Created-By: 1.6.0-beta2 (Sun Microsystems Inc.)
Main-Class: Test
可以根據第一種方法生成的 MANIFEST.MF 改
將*.mf 和.class放在一個目錄中
jar cvfm h.jar 11.mf Test.class
jar cvfm jar文件名 mf 文件名 .class文件
執行
java -jar hello.jar
java -jar jar文件全名
package com.lk.test打包
jar cvfm hh.jar test.mf com
package com.lk.test打包+配置文件
jar cvfm hh.jar test.mf com db.properties
就可以將db.properties放在和com并列的目錄下
如果使用了第三方jar包 : 要寫入.mf文件中
Manifest-Version: 1.0
Main-Class: lk.Test
Class-Path: lib/jxl.jar
另外在寫manifest.mf 文件的時候也有兩點務必注意
Main-Class: test.test Class: test.test 之間的一個空格,另外,行尾務必回車換行
===========jar幫助================
用法: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
選項包括:
-c 創建新的歸檔文件
-t 列出歸檔目錄
-x 解壓縮已歸檔的指定(或所有)文件
-u 更新現有的歸檔文件
-v 在標準輸出中生成詳細輸出
-f 指定歸檔文件名
-m 包含指定清單文件中的清單信息
-e 為捆綁到可執行 jar 文件的獨立應用程序指定應用程序入口點
-0 僅存儲;不使用任何 ZIP 壓縮
-M 不創建條目的清單文件
-i 為指定的 jar 文件生成索引信息
-C 更改為指定的目錄并包含其中的文件
如果有任何目錄文件,則對其進行遞歸處理。
清單文件名、歸檔文件名和入口點名的指定順序與 "m"、"f" 和 "e" 標志的指定順序相同。
示例 1:將兩個類文件歸檔到一個名為 classes.jar 的歸檔文件中:
jar cvf classes.jar Foo.class Bar.class
示例 2:使用現有的清單文件 "mymanifest" 并
將 foo/ 目錄中的所有文件歸檔到 "classes.jar" 中:
jar cvfm classes.jar mymanifest -C foo/ .
補充:
############
jar基本操作:
############
1. 創建jar文件
jar cf jar-file input-file(s)
c---want to Create a JAR file.
f---want the output to go to a file rather than to stdout.
eg: 1)jar cf myjar.jar query_maintain_insert.htm
2)jar cvf myjar.jar query_maintain_insert.htm
v---Produces verbose(詳細的) output.
3)jar cvf myjar.jar query_maintain_insert.htm mydirectory
4)jar cv0f myjar.jar query_maintain_insert.htm mydirectory
0---don't want the JAR file to be compressed.
5)jar cmf MANIFEST.MF myjar.jar yahh.txt
m---Used to include manifest information from an existing manifest file.
6)jar cMf MANIFEST.MF myjar.jar yahh.txt
M---the default manifest file should not be produced.
7)jar cvf myjar.jar *
*---create all contents in current directory.
2. 察看jar文件
jar tf jar-file
t---want to view the Table of contents of the JAR file.
eg: 1)jar vft yahh.jar
v---Produces verbose(詳細的) output.
3. 提取jar文件
jar xf jar-file [archived-file(s)]
x---want to extract files from the JAR archive.
eg: 1)jar xf yahh.jar yahh.txt(僅提取文件yahh.txt)
2)jar xf yahh.jar alex/yahhalex.txt(僅提取目錄alex下的文件yahhalex.txt)
3)jar xf yahh.jar(提取該jar包中的所有文件或目錄)
4. 修改Manifest文件
jar cmf manifest-addition jar-file input-file(s)
m---Used to include manifest information from an existing manifest file.
5. 更新jar文件
jar uf jar-file input-file(s)
u---want to update an existing JAR file.
posted on 2007-11-06 15:22
lk 閱讀(366)
評論(0) 編輯 收藏 所屬分類:
j2se