制作java可执行程序的方法

命令行方法:

1、 创建Manifest.txt文件,内容:

 

Main-Class: com.mkyong.awt.AwtExample

2、打包所有的class,包括Manifest.txt文件:

$ jar -cvfm run.jar Manifest.txt com/

3、run.jar即可在windows下双击鼠标执行(前提是要安装jre)。在linux用命令行执行:

$ java -jar run.jar

 

IDE方法:

用eclipse

1、右键点击工程,选择 export... 菜单:

      Create an Executable File from Eclipse Step 2.jpg

2、选择 java 下面的 Runnable JAR file:

       Create an Executable File from Eclipse Step 3.jpg

3、在launch configuration里选择包含main函数的类

       Create an Executable File from Eclipse Step 4.jpg

      

    1.   Extract required libraries into JAR - Extracts the actual .class files from the libraries your app uses and puts those .class files inside the runnable JAR. So, the runnable JAR will not only contain the .class files of your application, but also the .class files of all the libraries your application uses.

    2.   Package required libraries into JAR - Puts the actual JAR files of the libraries into your runnable JAR. Normally, a JAR file within a JAR file cannot be loaded by the JVM. But Eclipse adds special classes to the runnable JAR to make this possible.

    3.   Copy required libraries into sub folder next to JAR - Keeps the library JARs completely separate from the runnable JAR, so the runnable JAR will only contain the .class files of your application.

    一般情况下,选择2.

4、用launch4j可以给程序定制图标等东西。

 

打包好的jar文件,可以用 jar tf run.jar 查看其中的内容

转载于:https://www.cnblogs.com/welhzh/p/3555099.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值