首先写一个swing的窗口类,然后导出为Hello.jar。
Java代码
public class Hello {
public static void main(String[] args) {
HelloFrame frame = new HelloFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class HelloFrame extends JFrame {
public HelloFrame() {
setTitle("Hello Swing");
setSize(width, height);
}
public static final int width = 300;
public static final int height = 200;
}
在源程序的src目录下运行,使用java自带的签名工具产生签名文件,按照提示一步步完成产生key
keytool -genkey -keystore notepadKeyFile -alias notepadKey
其中,notepadKeyFile是生成的文件名称, notepadKey是别名。可以查阅到相应的证书信息。
用ant来为Hello.jar签名
Xml代码
<?xml version="1.0" encoding="UTF-8"?>
<project name="swing" basedir="." default="">
<property name="src.dir" value="${basedir}/src" />
<property name="dist.lib" value="${basedir}/dist" />
<!-- Directory structure of the project -->
<target name="all" depends="" description="generate Key to sign jars">
<signjar alias="notepadKey" storepass="hellojava" keypass="hellojava" keystore="${src.dir}/notepadKeyFile" verbose="true">