JNLP协议开发Java程序

写这篇文章前,参考了网上的一些资料没记地地址,如果你认为有抄袭了,请联系我

首先写一个swing的窗口类,然后导出为Hello.jar。

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 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">
<fileset dir="${dist.lib}">
<include name="*.jar" />
</fileset>
</signjar>
</target>
</project>

建立swing.jnlp文件

<?xml version="1.0" encoding="utf-8" ?>
<jnlp spec="1.0+" codebase="http://localhost/easy/" href="Hello.jnlp">
<information>
<title>NotePad V0.1</title>
<vendor>wendy</vendor>
<description>NotePad V0.1</description>
<description kind="tooltip">
www.ZigzagSoft.net (FreeWare)
</description>
<offline-allowed />
</information>
<security><!--权限设置-->
<all-permissions />
</security>
<resources>
<j2se version="1.6+" />
<jar href="Hello.jar" />
</resources>

<application-desc main-class="net.swi.Hello"><!--主类-->
</application-desc>
</jnlp>


将Hello.jnlp和Hello.jar复制到http://localhost/easy/ (这里我是用tomcat跑了一个easy的web项目)目录下,然后就是可以远程用Hello.jnlp来打开服务器的.jar文件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值