Java Web Start

JDK 1.5 新特性之(Java Web Start) 前言:当我们遇到以jnlp为后缀的文件的时候会感到很诧异,没关系读完这篇文件你就会明白了。 一、概述   在java开发的早期,重点被放在了客户端开发。语言中对于applet和安全下载的支持对于万维网(WWW)的发布看上去是个不错的主意。但是现实是java最大的成功在于服务器端,java的强大功能和适应性赢得了服务器端开发者的心。同时,客户端的开发落后了。棘手的开发问题限制了applet的效用... 阅读详情

http://today.java.net/pub/a/today/2005/08/11/webstart.html

Java Sketchbook: Getting Started with Java Web Startby Joshua Marinacci
08/11/2005

Many web developers long for a way to build applications with richer interfaces. They would love to build desktop applications with all of the power that client-side Java provides, but don't want to give up the ease of deployment that comes with web apps. How do you launch a program without downloading installers? How to you make it secure and safe to use? How do you update the program without asking your users to go download a new version? These are features that web app developers take for granted and don't want to give up in exchange for a richer interface. It may seem hopeless, but there is an answer: Java Web Start.

Java Web Start (JWS) is a technology that lets you deploy a desktop Java application directly from a web page. It provides security, safety, and automatic updates when you roll out new versions. It will even give your program an icon on the desktop. In short, Java Web Start gives you the power of a desktop app with the ease of deployment users expect from a web app.

This two-part series will tell you everything you need to know to start using Java Web Start. By the end of part one, you will have a simple running application that can be launched and updated from the web. Part two will cover security, optimized downloads, and how to polish your program to give it a professional shine.

What is Java Web Start?

Java Web Start is an implementation of the Java Network Launching Protocol (JNLP) specification. It provides a way to launch a desktop Java program from a web link and install it to your users' desktops. Once installed, JWS will check for updates every time the users run your program, ensuring they always have the most recent version installed.

In addition to its launch capabilities, Java Web Start also provides a protected sandbox for running untrusted applications. This is similar to the applet sandbox in a web browser. It allows users to run programs from potentially unsafe locations without worrying that the program could delete files, steal information, or replicate itself to other computers. In the age of viruses, worms, and spyware, this is a big concern. With Java Web Start, you can know that both you and your users will be protected.

Originally bundled as a separate download, Java Web Start is now included in the JRE. If you have J2SE 5.0 on your computer (or Java 1.4, on Mac OS X) then you already have Java Web Start installed and you can get started right away. While it does introduce a few new APIs (mainly for dealing with the sandbox), you can get started without writing any new code. You just need a JNLP descriptor file.

How It Works

Java Web Start works by using a special file called the JNLP descriptor, which is a small XML document that describes your application and its needs. This file lists the .jars that make up your program, the starting class with the main method, security settings, and most visibly, a splash screen and an icon. Together, these settings describe how the program is launched and how it looks to your users.

Once you've written a JNLP file, you can put it on your web server and make a link to it. When someone clicks on the link, their web browser will download the JNLP file and start the JWS application launcher. JWS will then download all of the .jars that make up your program (along with any other resources like images and icons), install an icon on the desktop (if requested), and then start your program. The next time the user runs the program from the desktop icon, JWS will check for any updated resources before starting the program again.

If this all sounds pretty complicated, don't worry. We'll start with a simple example so you can see how it all works. Imagine a virtual pet game where the player raises pirates, leading them on treasure hunts and boarding raids. The program could be called "My Pirate!". This is what its JNLP might look like.

<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="http://mypirate.com/downloads/" 
        href="mypirate.jnlp">
    <information>
        <title>My Pirate!</title>
    </information>
    <resources>
        <jar href="mypirate.jar"/>
    </resources>
    <application-desc main-class="mypirate.Startup"/>
</jnlp>

Let's go through this one line at a time. The first line contains the XML prolog. This is what tells a parser that what follows will be an XML file. This should be the same for any JNLP file. Next is the jnlp element, with two attributes, one for the href of the jnlp itself and one for the codebase, which says where the .jars and other resources will be downloaded from.

Inside the jnlp element are three sections: information, resources, and application-desc. information has purely descriptive content. The title specifies, as you would expect, the name of the program. This title will be used in the JWS control panel, for the name of the desktop icon, and in the platform-specific application manager, like the "Add and Remove Programs" control panel in Windows. The information section can contain other things like icons, a splash screen, or longer descriptions, but the title is enough to get started.

The resources section tells Java Web Start which .jars and other resources are required to run your program. These are all relative to the codebase attribute in the jnlp element. For example, the mypirate.jar file must be on my web server at the URL codebase plus href; in other words, http://mypirate.com/downloads/mypirate.jar. The resources section can also contain native libraries, extensions, properties, and other elements, but jar is the most important.

The last section, application-desc, specifies some attribute about the application. In this case I have told JWS that the main class of my program is mypirate.Startup. All JNLPs need this section so that JWS will know how to start the program. Without, it JWS would throw an exception the first time I try to run the program.

Deploying "My Pirate!"

In theory, you can just upload your JNLPs, .jars, and other files to your website and call it a day. In practice, however, it's not that simple. First, you must make sure you upload your files to the same place specified in the codebase attribute of your JNLP. For "My Pirate!" I would have to upload the files to http://mypirate.com/downloads/. Even if I load the JNLP file from somewhere else (generated by a servlet on another server, perhaps), Java Web Start will still load the .jars relative to the codebase specified in the JNLP file.

The second common stumbling block is the MIME type. Most web servers don't yet understand how to serve jnlp files. If I just dropped the files into a standard Apache server, the web browser would probably think the file is plain text and show it in a browser window rather than calling Java Web Start. I have to tell my web server to serve any file with a .jnlp extension as application/x-java-jnlp-file. Each web server has its own configuration, but for Apache, you can add a line to your httpd.conf next to the other AddType lines, like this:

AddType application/x-java-jnlp-file .jnlp

That should be it. If I point my web browser at http://mypirate.com/downloads/mypirate.jnlp, I will see the JNLP downloaded and my program will start. Depending on my particular Java Web Start implementation, it may ask me if I want to keep this JNLP as a permanent application. If I say yes, it will create a program icon on my desktop or hard drive.

Add a Description and Icon, and Splash Screen Building

A plain JNLP file for my program works, but it's missing a few things. The "Add/Remove Programs" control panel in Windows will list it simply as "My Pirate!" with no further information about who made the program or what it does. It has no splash screen when it starts, and it uses the generic coffee cup icon. In short, it doesn't feel professional. Fortunately, the Java Web Start developers thought of this and provided easy ways to add some polish.

Add an Icon

To add an icon you must add an <icon> element to the information section of your JNLP. The icon element needs an href attribute containing the URL of the icon to use. This icon can be a GIF or a JPEG, or another platform-dependent format (BMP, ICO, PICT). Be sure to test the platforms you are targeting to determine which formats will work. Mustang will improve PNG support to give icons full transparency.

<information>
    <title>My Pirate!</title>
    <icon href="icon.png"/>
</information>

The icon will be loaded relative to the codebase, so I upload it to the same location on my web server. Now my application on disk will look like Figure 2 instead of Figure 1.

Standard JWS Icon
Figure 1. Standard JWS icon

Custom Pirate Icon
Figure 2. Custom pirate icon

Add a Splash Screen

Java Web Start also supports splash screens. A splash screen is an image that will appear while the program is launching. It provides feedback to let the user know the program hasn't crashed during a potentially long initialization routine. A splash screen also serves as a visual identifier for your program and your company, creating a consistent feel throughout. You can create a splash screen by providing a second icon with its kind set to splash.

<information>
    <title>My Pirate!</title>
    <icon href="icon.png"/>       
    <icon href="splash.png" kind="splash"/> 
</information>

Which will look like Figure 3:

'My Pirate!' Splash Screen
Figure 3. "My Pirate!" splash screen

If you don't provide a splash screen, Java Web Start will use another icon element in your application. If there is no icon element at all, then it will generate a splash screen using the description and title of your program. This typically is ugly, however, so I highly recommend you provide your own splash screen.

Note: splash screens do not currently work on Mac OS X.

Updating an Application

Updating your application is very easy. Just recompile your code and upload your new .jars to the web server. The next time one of your users starts the program (either via a link on a website or from an icon on the desktop), JWS will check for the new .jars. If the web server's .jar file timestamps are newer than the .jars on disk, then JWS will download the new .jars, add them to the cache, and then start your program. Java Web Start also provides a way to send out incremental updates, where only the changes to a .jar are downloaded instead of the entire .jar, but that is beyond the scope of this article and is only useful for large (multi-megabyte) applications. For more information on JarDiffs, take a look at the " Mapping Requests to Resources" section of the Java Web Start Download Servlet Guide.

Removing an Application

Java Web Start makes installing an application super easy, so it's nice that uninstalling is easy, as well. There is a program called the Application Manager that lets you manage the Web Start programs installed on your computer. This is part of the Java Control Panel on Windows and Linux. On Mac OS X, it is an application in the /Applications/Utilities/Java directory. You can also run the javaws program from the command line with no arguments to get to the cache viewer. The manager program shows information about each JWS application and allows you to start, update, or remove them. It also lets you create a desktop icon for a JWS app if you want it to feel more native.

Conclusion

Java Web Start is a great technology for deploying desktop Java applications without the usual headaches of desktop apps. In the first part of this article you have learned how to create a simple application, launch it from a web page, update it, and how to improve the look of the application with icons and a splash screen. Please join me in the second part, where we will look at the Java Web Start security model, use Pack 200 to decrease download time, and add some extra polish with documentation and file associations.

Resources

Java学习day088 部署Java程序(五)(Java Web Start:发布Java Web Start应用、JNLP API) 使用的教材是java核心技术卷1,我将跟着这本书的章节同时配合视频资源来进行学习基础java知识。 day088 部署Java程序(五)(Java Web Start:发布Java Web Start应用、JNLP API) ... 阅读详情

相关推荐

Java Web Start技术详解与实战入门

Java Web Start(简称 JWS)是一项基于标准 HTTP 协议的 Java 应用部署技术,旨在实现“一次编写,随处运行”的跨平台交付能力。通过浏览器或直接调用.jnlp文件,JWS 能够自动从服务器下载 Java 应用程序,并在本地 JVM 中安全运行,无需用户手动安装或配置复杂的依赖环境。其核心架构依赖于 JNLP(Java Network Launch Protocol)协议,结合本地缓存、安全沙箱和自动版本更新机制,显著降低了传统桌面应用部署的复杂性。JWS 通过。

weixin_42146230的博客 979

Java Web Start 开发向导

前言: 在java开发的早期,重点被放在了客户端开发。语言中对于applet和安全下载的支持对于万维网(WWW)的发布看上去是个不错的主意。但是现实是java最大的成功在于服务器端,java的强大功能和适应性赢得了服务器端开发者的心。同时,客户端的开发落后了。棘手的开发问题限制了applet的效用,开发者被迫转向基于浏览器的瘦客户端。Java Web Start 软件使您可以从 Web 下载和运行...

fanxiaobin 5505

Java Applet与Java Web Start的通信与安全

本篇博文深入探讨了Java Applet间的通信机制,如何在浏览器中显示信息,以及Java Web Start的应用发布技术。详细介绍了Applet间通信的高级技术,包括使用AppletContext接口进行交互,以及如何通过AppletContext在浏览器中显示信息和导航到其他页面。同时,讨论了Java安全模型的核心概念——沙箱,以及代码签名的重要性,确保了Java应用的安全执行。最后,阐述了Java Web Start的特性及其在应用发布中的作用。

weixin_34268462的博客 995

Cisco ASDM-IDM not able to be installed because of Java Runtime Environment is not installed

Environment:ASA5510ASA version 8.0(4)ASDM version 6.2(5)53OS: windows 2008 R2 Situation:Use Google Chrome access ASA5510, download ASDM-IDM package. Filename is dm-launcher.exe.Double click got follo...

Cyber Security Memo 382

Oasys安装教程

在基环境下执行然后去 C:\Users.condarc打开 .condarc这个文件 删除干净里面的东西。

weixin_44254178的博客 1295

Zabbix监控联想服务器XCC的SNMPv3配置实战

本文详细介绍了如何通过SNMPv3协议配置Zabbix监控联想服务器XCC的实战方法。文章从安全角度阐述了选择SNMPv3的必要性,并分步讲解了在XCC中启用SNMPv3、创建认证用户,以及在Zabbix中导入专用模板、创建主机并关联模板的完整流程,帮助运维人员实现对服务器硬件健康状态的自动化、安全监控。

weixin_29210727的博客 464

Java Web Start is not available for the JVM version running Jenkins

Java Web Start is not available for the JVM version running Jenkins

gongwei1121355014的博客 1783

随机化策略——随机变量rand、约束constraint、权重dist、随机数产生示例

文章目录一、随机变量类型1.1.rand随机变量1.2.randc随机变量二、随机化约束2.1.constraint指定约束范围2.1.1.关系操作符约束(>、<、=、>=、<=)2.1.2.范围操作符约束(inside)2.1.3.权重分布约束(dist)2.1.4.条件约束(if-else; ->)三、启动随机化——randomize( )函数四、关闭或打开随机变...

Mr.翟的博客 2万+

java web start error_JAVA web start 载入程序错误

满意答案congyun5522013.09.04采纳率:43%等级:13已帮助:9092人点击:开始→运行→cmd→复制/粘贴以下命令(可以每次一条也可以全部复制粘贴进去)netsh winsock resetregsvr32 Mshtml.dllregsvr32 Urlmon.dllregsvr32 Msjava.dllregsvr32 Browseui.dllregsvr32 Olea...

weixin_31630667的博客 1212

别再只用串口助手了!用LabVIEW给STM32F103C8T6做个专属上位机(附完整源码)

本文详细介绍了如何利用LabVIEW为STM32F103C8T6开发定制化上位机,替代传统串口助手,实现高效数据交互。内容涵盖硬件架构设计、STM32固件优化、LabVIEW上位机开发技巧及工业级应用案例,特别适合需要实时数据采集与处理的工控场景。

weixin_42524762的博客 367

PyTorch实战(19)——变分自编码器(Variational Autoencoder,VAE)

变分自编码器 (Variational Autoencoder, VAE) 是一种结合了自编码器和概率建模的生成模型,通过编码器将输入数据映射到潜在空间中的概率分布,并通过解码器将从潜在空间采样得到的潜在变量映射回原始数据空间,实现了数据的生成和特征学习。本节中,将介绍变分自编码器的基本概念,并使用 PyTorch 实现变分自编码器生成新图像。

盼小辉丶的博客 2866

asdm不能登录问题;浏览器必须是ie,不能是chrome或者firefox;java的版本,尤其是安全等级和例外需要调整...

asdm不能登录问题;浏览器必须是ie,不能是chrome或者firefox;java的版本,尤其是安全等级和例外需要调整

weixin_34102807的博客 425

OpenClaw实战一|企业微信AI客服数字员工:自动应答+工单创建+数据统计,零代码3天落地

OpenClaw做企业微信AI客服数字员工,真正的价值不是“能自动回复”,而是把“咨询-应答-工单-统计-复盘”全流程闭环。对中小企业来说,不用招专职AI开发、不用买昂贵客服系统,一台服务器、零代码配置,就能拥有媲美大厂的智能客服能力。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 515

java web start

Java Web Start 并不是一个库或工具,而是一个已经废弃的技术。它曾经是 Java 的一部分,用于简化 Java 应用程序的部署和启动,但随着技术的发展,它已经被废弃了。从 Java 9 开始,Oracle 宣布 Java Web Start 不再是 Java SE 的一部分,并且在后续版本中逐渐被移除。

qq_62784677的博客 786

解码器选型参数,结构原理,工艺与注意问题总结

解码器芯片(Decoder Chip)是电子设备中的一个重要组件,通常用于处理、解释和输出存储在某种编码格式中的数据或信号。本文对解码器的工作原理,结构特点,工艺流程,选型参数及设计注意事项进行总结。

fydar的博客 1169

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Java Web Start入门基础教程

关于Web Start的JNLP Specification可以到sun网站http://java.sun.com/products/javawebstart/download-spec.html下载。 下面是用最简单的HelloWorld方法实现一个Java Web Start的例子,工程webstart目录结构如下:   目录说明如下: images :存放*.jnlp文件中定义的...

weixin_33778544的博客 3671

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Java Web Start 如何运行

需要做如下配置即可:1.将javaws.exe配置到classpath路径下。2.将你的类打包成一个jar文件。3.写一个file.jnlp文件内容如下:   codebase="file:C:/Users/limx/Desktop/Temporary"   href="filechooser.jnlp">FileChooser demo applicationMindview Inc.       Jnlp File chooser Application

limx_liam的专栏 1946

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

java web start launcher,Java Web Start 1.0 FAQ (2)-JSP教程,资料/其它

can i implement my own javatm web start?the underlying technology for javatm web start, the java network launching protocol and api, is being developed through the java community process.http://java.s...

weixin_36125588的博客 387

java web start 安装,Java Web Start驱动安装

I'm trying to figure out the best way to install my Java app on client computers.The main guideline here is that these clients are computer illiterates - so the less fuss the better.I was thinking of ...

weixin_31304817的博客 325

Java网络加载协议(JNLP)及Java Web Start

Java网络加载协议(JNLP)及Java Web Start翻译:cheramimail:cherami@163.net 原文:http://java.sun.com/jdc/JDCTechTips/2001/tt0530.html在java开发的早期,重点被放在了客户端开发。语言中对于applet和安全下载的支持对于万维网(WWW)的发布看上去是个不错的主意。但是现实是java最大的成功在

解惑 7692
上一篇: Difference between PCDATA and CDATA
下一篇: Deploy an SWT application using Java Web Start
java_augur
博客等级 码龄22年 67粉丝 64原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值