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: