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!