jar 如何打包

来源:百度知道 编辑:UC知道 时间:2024/06/05 13:12:21
用helloworld.class 为例作详细说明,急先给20分,回答得好再加30
一定要用具体的例子
====================
提示

:\编译~1\hello>jar cmf my.jar A.class
ava.io.FileNotFoundException: my.jar (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.tools.jar.Main.run(Main.java:122)
at sun.tools.jar.Main.main(Main.java:903)

如下:(这算示例1吧)
jar cvf my.jar helloword.class
将helloword.class打包为my.jar
说明:
-c 创建新的包
-v 生成详细输出到你的dos窗口上
-f 指定你的包名

示例2:将两个class文件打包到一个名为 'classes.jar' 的包中:
jar cvf classes.jar Foo.class Bar.class

示例3:将一个名为file文件夹打包到一个名为myfile.jar的包中
jar cvf myfile.jar file

示例4:将一个名为file文件夹下的所有内容打包到一个名为myfile.jar的包中
jar cvf myfile.jar file/*

上面的例子dos和文件都是在当前目录,
还有更多的例子,也不知道你还有哪些不知道

生成直接可以运行的jar包
http://hi.baidu.com/lovebwf/blog/item/602869a78849c090d14358ef.html

最简单的方法就是用Eclipse等IDE直接自动打包。