如何打jar包

来源:互联网 发布:抽签软件 编辑:程序博客网 时间:2024/06/03 02:32

方法一:利用命令行

源文件Hello.java,编译后Hello.class主类Hello
1.cd到文件所在目录
2.打包,输入jar cvfe hello.jar Hello Hello.class
//cvfe中的e表示指定主类,      Hello是主类名
3.运行 输入java -jar hello.jar 控制台输出hello world

方法二:用Eclipse(工程没有引用外部jar包时,直接导出)

选中工程---->右键,Export...--->Java--->JAR file--->next-->选择jar file的路径及名称-->next-->next---> 选择main class--->finish.