`
dasheng
  • 浏览: 148019 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jnlp 与java web start

阅读更多

1,什么是jnlp:

java network launch protocol(java网络发布协议)。是保留applet的优点的前提下,通过一个jnlp程序,你可以在客户机上下载和安装单机版的java应用程序。

jnlp应用程序可以在运行时从因特网上动态下载资源,并且能够在用户连接到因特网的情况下,自动检查程序的版本。

 

2,FileChooser Test .java:

 

//: gui/jnlp/JnlpFileChooser.java
// Opening files on a local machine with JNLP.
// {Requires: javax.jnlp.FileOpenService;
// You must have javaws.jar in your classpath}
// To create the jnlpfilechooser.jar file, do this:
// cd ..
// cd ..
// ut
package gui.jnlp;
import javax.jnlp.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class JnlpFileChooser extends JFrame {
  private JTextField fileName = new JTextField();
  private JButton
    open = new JButton("Open"),
    save = new JButton("Save");
  private JEditorPane ep = new JEditorPane();
  private JScrollPane jsp = new JScrollPane();
  private FileContents fileContents;
  public JnlpFileChooser() {
    JPanel p = new JPanel();
    open.addActionListener(new OpenL());
    p.add(open);
    save.addActionListener(new SaveL());
    p.add(save);
    jsp.getViewport().add(ep);
    add(jsp, BorderLayout.CENTER);
    add(p, BorderLayout.SOUTH);
    fileName.setEditable(false);
    p = new JPanel();
    p.setLayout(new GridLayout(2,1));
    p.add(fileName);
    add(p, BorderLayout.NORTH);
    ep.setContentType("text");
    save.setEnabled(false);
  }
  class OpenL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      FileOpenService fs = null;
      try {
        fs = (FileOpenService)ServiceManager.lookup(
          "javax.jnlp.FileOpenService");
      } catch(UnavailableServiceException use) {
        throw new RuntimeException(use);
      }
      if(fs != null) {
        try {
          fileContents = fs.openFileDialog(".",
            new String[]{"txt", "*"});
          if(fileContents == null)
            return;
          fileName.setText(fileContents.getName());
          ep.read(fileContents.getInputStream(), null);
        } catch(Exception exc) {
          throw new RuntimeException(exc);
        }
        save.setEnabled(true);
      }
    }
  }
  class SaveL implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      FileSaveService fs = null;
      try {
        fs = (FileSaveService)ServiceManager.lookup(
          "javax.jnlp.FileSaveService");
      } catch(UnavailableServiceException use) {
        throw new RuntimeException(use);
      }
      if(fs != null) {
        try {
          fileContents = fs.saveFileDialog(".",
            new String[]{"txt"},
            new ByteArrayInputStream(
              ep.getText().getBytes()),
            fileContents.getName());
          if(fileContents == null)
            return;
          fileName.setText(fileContents.getName());
        } catch(Exception exc) {
          throw new RuntimeException(exc);
        }
      }
    }
  }
  public static void main(String[] args) {
    JnlpFileChooser fc = new JnlpFileChooser();
    fc.setSize(400, 300);
    fc.setVisible(true);
  }
} ///:~

 

 

3,用于启动的jnlp文件:

 

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec = "1.0+"
  codebase="file:E:/myeclpse6.0/thinkingjava/bin/gui/jnlp"
  href="filechooser.jnlp">
  <information>
    <title>FileChooser demo application</title>
    <vendor>Mindview Inc.</vendor>
    <description>
      Jnlp File chooser Application
    </description>
    <description kind="short">
      Demonstrates opening, reading and writing a text file
    </description>
    <icon href="mindview.gif"/>
    <offline-allowed/>
  </information>
  <resources>
    <j2se version="1.3+"
      href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="jnlpfilechooser.jar" download="eager"/>
  </resources>
  <application-desc
    main-class="gui.jnlp.JnlpFileChooser"/>
    <security><all-permisssion><security>
</jnlp>

4,文件需要通过以下命令打成jar包:jar cvf gui/jnlp/jnlpfilechooser.jar gui/jnlp/*.class

 

配置文件的 codebase指明jar文件和jnlp文件的目录本地或服务器的目录。

 

 

5,使用introspector(内省器)抽取beaninfo

 

java的设计者希望能提供一个标准的工具,不仅要使用bean用起来简单,而且对于创建复杂的bean也能提供一个标准的

方法。这个工具就是IntroSpector类,这个类最重要的就是静态的getBeanInfo()方法,向这个方法传递一个Class对象引用,它能够完全侦测这个类,然后返回一个BeanInfo对象,通过这个对象得到Bean的属性、方法、事件。

 

//: gui/BeanDumper.java
// Introspecting a Bean.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.lang.reflect.*;
import static net.mindview.util.SwingConsole.*;

public class BeanDumper extends JFrame {
  private JTextField query = new JTextField(20);
  private JTextArea results = new JTextArea();
  public void print(String s) { results.append(s + "\n"); }
  public void dump(Class<?> bean) {
    results.setText("");
    BeanInfo bi = null;
    try {
      bi = Introspector.getBeanInfo(bean, Object.class);
    } catch(IntrospectionException e) {
      print("Couldn't introspect " +  bean.getName());
      return;
    }
    for(PropertyDescriptor d: bi.getPropertyDescriptors()){
      Class<?> p = d.getPropertyType();
      if(p == null) continue;
      print("Property type:\n  " + p.getName() +
        "Property name:\n  " + d.getName());
      Method readMethod = d.getReadMethod();
      if(readMethod != null)
        print("Read method:\n  " + readMethod);
      Method writeMethod = d.getWriteMethod();
      if(writeMethod != null)
        print("Write method:\n  " + writeMethod);
      print("====================");
    }
    print("Public methods:");
    for(MethodDescriptor m : bi.getMethodDescriptors())
      print(m.getMethod().toString());
    print("======================");
    print("Event support:");
    for(EventSetDescriptor e: bi.getEventSetDescriptors()){
      print("Listener type:\n  " +
        e.getListenerType().getName());
      for(Method lm : e.getListenerMethods())
        print("Listener method:\n  " + lm.getName());
      for(MethodDescriptor lmd :
          e.getListenerMethodDescriptors() )
        print("Method descriptor:\n  " + lmd.getMethod());
      Method addListener= e.getAddListenerMethod();
      print("Add Listener Method:\n  " + addListener);
      Method removeListener = e.getRemoveListenerMethod();
      print("Remove Listener Method:\n  "+ removeListener);
      print("====================");
    }
  }
  class Dumper implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      String name = query.getText();
      Class<?> c = null;
      try {
        c = Class.forName(name);
      } catch(ClassNotFoundException ex) {
        results.setText("Couldn't find " + name);
        return;
      }
      dump(c);
    }
  }
  public BeanDumper() {
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    p.add(new JLabel("Qualified bean name:"));
    p.add(query);
    add(BorderLayout.NORTH, p);
    add(new JScrollPane(results));
    Dumper dmpr = new Dumper();
    query.addActionListener(dmpr);
    query.setText("frogbean.Frog");
    // Force evaluation
    dmpr.actionPerformed(new ActionEvent(dmpr, 0, ""));
  }
  public static void main(String[] args) {
    run(new BeanDumper(), 600, 500);
  }
} ///:~

分享到:
评论

相关推荐

    JNLP

    JNLP与Java Web Start紧密关联,Java Web Start是一个基于浏览器的技术,允许用户通过点击一个链接来下载和运行Java应用程序。它提供了“一次点击”安装,自动更新,以及离线运行等功能。 3. **安全特性**: JNLP...

    Java Web Start

    Java Web Start在浏览器端与服务器端之间架起了一座桥梁,使得Java应用程序的分发和更新变得更加简单。 Java Web Start的工作原理基于Java网络启动协议(JNLP,Java Network Launch Protocol)。JNLP文件是一个XML...

    Java web Start初级教程

    2. **构建webstart目录结构**: - `images`:存放jnlp文件中定义的图标文件。 - `jar`:存放已打包的JAR文件。 - `jnlp`:存放描述文件(*.jnlp)。 - `src`:存放源代码。 - `WEB-INF/classes`:存放编译后的...

    JNLP ant webstart sign genkey sample

    标题“JNLP ant webstart sign genkey sample”涉及到的是Java网络启动(Java Web Start,JWS)技术,以及如何使用Ant构建工具来签名JNLP应用。在Java Web Start中,JNLP(Java Network Launch Protocol)是用于启动...

    java web start

    对于无法在JDK 1.5上运行Java Web Start的情况,可能是因为该版本的Java与特定的Java Web Start版本存在兼容性问题,或者需要特定的配置。文件"javaws-1_0_1_02-win-int(1).exe"看起来是一个早期版本的Java Web ...

    JNLP开发(JWS)

    #### JNLP与Java WebStart:概念解析 JNLP(Java Network Launching Protocol),作为一项由Sun Microsystems在2000年提出的规范(JSR 56),为Java应用程序提供了一种通过网络分发和执行的机制。这一技术的核心...

    利用 Java Web Start发布你用java程序

    #### JWS——Java Web Start 的功能与优势 Java Web Start(简称 JWS)是 Sun Microsystems(现 Oracle)为解决 Java 应用程序部署和更新问题而开发的一项技术。它是 JSR-56 规范的一部分,旨在提供一种简便的方法...

    Deploying Java Web Start Applications on the JBoss Application Server

    当用户通过浏览器点击指向特殊格式的JNLP(Java Network Launching Protocol)执行文件链接时,会启动Java Web Start程序。随后,Java Web Start会自动从Web服务器下载应用程序所需的文件,缓存一部分,并启动描述中...

    深入探索Java Web Start:简化Java应用部署与更新

    Java Web Start,也称为Java Network Launch Protocol(JNLP),是Oracle提供的一种技术,用于从Web上启动和自动更新Java应用程序。它允许用户通过一个Web链接启动富客户端Java应用程序,同时确保应用程序始终保持...

    java web start教程

    Java Web Start(JWS)是SUN公司推出的一项技术,用于通过Web来部署和发布Java应用程序,无论是Application还是Applet。这项技术在初次运行时会下载程序,之后的版本更新和维护都由JWS自动处理,极大地简化了客户端...

    用java web start来发布jbpm(三)

    3. **打包JNLP文件**:JNLP(Java Network Launch Protocol)文件是Java Web Start应用的核心,它描述了应用程序的元数据,如主类、资源、权限等。博主会指导如何创建并配置JNLP文件,以便Java Web Start能够正确地...

    Using Java Web Start with Oracle E-Business Suite (Doc ID 2188898.1)

    ### 使用Java Web Start与Oracle E-Business Suite #### 一、关于Java Web Start ##### 1.1 什么是Java Web Start? Java Web Start提供了一种浏览器独立架构,用于将基于Java技术的应用程序部署到客户端桌面。...

    基于Java Web Start技术的VFP考试系统的设计与实现.pdf

    "基于Java Web Start技术的VFP考试系统的设计与实现" 这篇文章主要介绍了基于Java Web Start技术的VFP考试系统的设计与实现。该系统应用了Java Web Start技术,包括考试、教师、教务三大模块,使得考试系统更加灵活...

    LIFERAY + JAVA WEB START + OSWORKFLOW设计器

    JAVA WEB START(JNLP)是Java平台的一项技术,它允许用户通过Web浏览器方便地下载和运行Java应用程序。而OSWorkflow则是一个轻量级的工作流引擎,用于设计和实现复杂的业务流程。 首先,Liferay Portlet是Liferay...

    JWS java web start

    JNLP(Java Network Launch Protocol)是与JWS紧密关联的一个组件,它是JWS应用程序的描述文件,包含应用程序的元数据、依赖库、主类等信息,用于指导JWS如何下载和启动应用程序。 总的来说,Java Web Start为...

    webstart

    WebStart是Oracle公司(原Sun Microsystems)推出的一种基于Java的网络启动技术,它利用Java Network Launch Protocol (JNLP) 文件来启动和管理应用程序。WebStart的主要优点在于提供了一种便捷的方式,让用户通过...

    创建与部署Java Web Start的步骤

    (1)本资源为Head First Java(第二版)的第17章chap17(本章在官网资源代码中没有这个代码,且书中描述模糊)为初学者打开门窗; (2)本资源根据书中例子,查询网上资料,自己总结,验证过可行,若不可行看自己搭建...

Global site tag (gtag.js) - Google Analytics