---
title: "剖析一个JNLP文件"
author: "cjx186"
date: "2009-12-02T22:17:10Z"
tags: []
slug: "jnlp"
draft: false
lastmod: "2009-12-02T22:17:10Z"
id: 539575
url: "https://xml.iteye.com/blog/539575"
---

剖析一个JNLP文件
JNLP是一个XML文档，有一个根元素和四个子元素组成

jnlp 元素是根元素，它包含：
	一个 spec 属性 (用于说明规范的版本，可以省略)
	一个 href 属性 (指向 JNLP 文件本身位置的 URL)
	一个 codebase 属性 (在 href 中指定的所有相对 URL 都以这个 URL 为基准)

information 是个子元素，它包含：
	应用程序和厂商的名字
	应用程序主页的 URL
	一个可选的、纯文本的应用程序描述
	表示该应用程序的图形文件图标的 URL

security 子元素可以用于请求不受限制的访问。 

resources 子元素用于指定所有资源，如作为应用程序一部分的 Java 类文件、本机库和系统属性。使用 os、 arch 和 locale 属性，资源定义可以限定到特定操作系统、体系结构或者位置。它包含六个可能的子元素：
	jar (指定一个 JAR 文件，该文件是应用程序的类路径的一部分)
	nativelib (指定包含本机库的 JAR 文件)
	j2se (指定支持应用程序的 J2SE JRE 版本，以及 JVM 的标准参数)
	property (定义通过 System.getProperty 和 System.getProperties 方法可使用的系统属性)
	package (指定使用的包)
	extension （指定使用的扩展)

application-desc 子元素表明 JNLP 文件启动的是一个应用程序而不是 applet。


```xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Application to Add Apples and Oranges -->
<jnlp
  spec="1.0+"
  codebase="http://@HOST@:@PORT@/fruits/client_app"
  href="fruit_@TIMESTAMP@.jnlp">
<information>
<title>Fruit_Salad_Application</title>
<vendor>Fruit_Salad_Elementary_School</vendor>
<homepage href="docs/help.html"/>
<description>Fruit_Salad_App</description>
<description kind="short">An application that adds apples and oranges.</description>
<icon href="images/fruit_salad_icon.gif"/>
<!--offline-allowed -->
</information>
<security>
  <all-permissions/>
</security>
<resources>
<j2se version="1.2+" initial-heap-size="64m" maximum-heap-size="64m"/>
<jar href="jars/client.jar"/>
<jar href="jars/packaged_data_@TIMESTAMP@.jar" download="eager"/>
</resources>
<application-desc main-class="FruitProcessor">
  <argument>@TIMESTAMP@</argument>
  <argument>@HOST@</argument>
  <argument>@PORT@</argument>
  <argument>@DATA.FILE.NAME@</argument>
</application-desc>
</jnlp>
```