merlin

精益求精

孤鸿

导航

【jar】打包命令

jar cvf filename.jar a.class b.class 

打包带package的

jar cvf test.jar foldname\*

打包可执行jar包

 

来个小例子试试看:

我们只有一个HelloWorld,如下:   

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println(args[0]);
    }
}

javac HelloWorld.java

jar cvf hello.jar HelloWorld.class

 

jar包中多了MANIFEST.MF

 

Manifest-Version: 1.0 
  Created-By: 1.4.2 (Sun Microsystems Inc.) 

修改之,第三行加入

Manifest-Version: 1.0 
  Created-By: 1.4.2 (Sun Microsystems Inc.) 
  Main-Class: HelloWorld

jar umf MANIFEST.MF hello.jar

 

java -jar hello.jar helloworld!

结果输出:helloworld!

posted on 2014-08-18 17:32  天地一连线_孤鸿挂飘渺  阅读(236)  评论(0编辑  收藏  举报