制作 java 可运行jar

1、先写个swing窗体

package test;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Show {

 /**
  * @param args
  */
 public static void main(String[] args) {
  JFrame.setDefaultLookAndFeelDecorated(true);
  JFrame frame = new JFrame("hello world");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JLabel label = new JLabel("hello");
  frame.getContentPane().add(label);
  frame.pack();
  frame.setVisible(true);
 }

}

 

将class拷贝到指定目录,进入命令行并切换到目录。

jar cvf test.jar test/Show.class 打jar包,将生成的test.jar中MANIFEST.MF解压,在末行添加入口类Main-Class:空一格test.Show回车

大致如下:

Manifest-Version: 1.0
Created-By: 1.7.0_03 (Oracle Corporation)
Main-Class: test.Show
--这里是空行

 

然后更新test.jar中MANIFEST.MF文件

jar umf MANIFEST.MF test.jar

 

finish!双击运行。找不到引用类,就设置MANIFEST.MF中Class-Path:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值