命令行方法:

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... 菜单:

      

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

       

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

       

      

    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 查看其中的内容

最新文章

  1. Swift控制器加载xib Swift Controller'view load from xib
  2. MacBook 显示隐藏文件夹命令
  3. [redis] Jedis 与 ShardedJedis 设计
  4. ...python の 学习
  5. 【转】Java中只有按值传递,没有按引用传递!
  6. Red Hat Enterprise Linux x86-64 上安装 oracle 11gR2
  7. Altium Designer规则
  8. springMVC中得到request对象,session对象
  9. JDBC详解系列(三)之建立连接(DriverManager.getConnection)
  10. python中 functools模块 闭包的两个好朋友partial偏函数和wraps包裹
  11. gcc使用及动静态库制作
  12. Codeforces 1120 简要题解
  13. 借助Algorithmia网站API:用AI给黑白照片上色,复现记忆中的旧时光
  14. textarea 赋值的方法
  15. Spark项目之电商用户行为分析大数据平台之(七)数据调研--基本数据结构介绍
  16. 记一次Apache Carbondata PR的经历
  17. std 与标准库
  18. 简单的图形学(三)——光源
  19. windows 批处理文件中引用日期
  20. Javascript中的感叹号和函数function

热门文章

  1. 协同滤波 Collaborative filtering 《推荐系统实践》 第二章
  2. python - PipeMapRed.waitOutputThreads(): subprocess failed with code 1
  3. jboolean
  4. java导出excel报表
  5. Event-based Asynchronous Pattern Overview基于事件的异步模式概览
  6. 数据库MySQL-Oracle-DB2-SQLServer分页查询
  7. Android下 ionic view 无法登录
  8. EJB3Persistence开发手册-原生SQL查询(NativeSQL)
  9. [经验] - JQuery.Ajax + 跨域 (crossDomain) + POST + JSON + WCF RESTful, 5大陷阱和解决方案
  10. Java [Leetcode 165]Compare Version Numbers