Java Web Start相关(包括jnlp、keytool、jarsigner)

     Sun提供了一种方式来通过网络发布Java程序,这就是Java Web Start。用户点击某个链接,其实际上是指向jnlp文件,运行后会自动从指定的地址下载相应的文件。

 

1.加入mime类型(web.xml或服务器的配置文件中)

  <mime-mapping>
    <extension>jar</extension>
    <mime-type>application/x-java-archive</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>jnlp</extension>
    <mime-type>application/x-java-jnlp-file</mime-type>
  </mime-mapping>

 

 

2.编辑jnlp文件

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://localhost:8080/TESTWeb" href="TESTLauncher.jnlp">
  <information>
    <title>TEST</title>
    <vendor>Vendor</vendor>
    <homepage href="TESTLauncher.html" />
    <description>TEST DESC</description>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se version="1.3+" />
    <jar href="TEST.jar" />
    <jar href="lib/alloy.jar" />
    <jar href="lib/baseframe-client.jar" />
    <jar href="lib/baseframe-server.jar" />
    <jar href="lib/baseframe-util.jar" />
    <jar href="lib/baseframe-upload.jar" />
    <jar href="lib/commons-codec-1.3.jar" />
    <jar href="lib/commons-dbcp-1.2.2.jar" />
    <jar href="lib/commons-fileupload-1.2.1.jar" />
    <jar href="lib/commons-httpclient-3.1.jar" />
    <jar href="lib/commons-io-1.4.jar" />
    <jar href="lib/commons-logging-1.1.jar" />
    <jar href="lib/commons-pool-1.3.jar" />
    <jar href="lib/component.jar" />
    <jar href="lib/components.jar" />
    <jar href="lib/dom4j-1.5.2.jar" />
    <jar href="lib/EvalExp.jar    " />
    <jar href="lib/explorer.jar" />
    <jar href="lib/jacob.jar" />
    <jar href="lib/javax.servlet.jar" />
    <jar href="lib/jaxen-1.1-beta-7.jar" />
    <jar href="lib/jbcl.jar" />
    <jar href="lib/jcommon-1.0.0.jar" />
    <jar href="lib/jfreechart.jar" />
    <jar href="lib/jxl.jar" />
    <jar href="lib/log4j-1.2.8.jar" />
    <jar href="lib/OpenSwing.jar" />
    <jar href="lib/Oracle12.jar" />
    <jar href="lib/resource.jar" />
    <jar href="lib/swing-layout-1.0.jar" />
    <jar href="lib/UserManager.jar" />
  </resources>
  <application-desc main-class="Test.RunCS" />
</jnlp>

 

 

3.为jar文件进行签名

首先,产生keystore

keytool -genkey -keystore TEST.keystore -alias TESTWeb

然后,进行签名

jarsigner -keystore TEST.keystore -storepass <yourpass> TEST.jar TESTWeb
for %%F in (lib/*.jar) do jarsigner -keystore TEST.keystore -storepass <yourpass> %%F TESTWeb

要确保所有的jar文件都进行签名

 

4.主jar文件中的manifest指定运行的main类

  Manifest-Version: 1.0
  Main-Class: Test.RunCS

 

  注意:Main-Class后要有一空行

你可能感兴趣的:(java,Web,jar,J2SE,resources,encoding)