'JAVA'에 해당되는 글 51건

  1. 2011.09.20 Java Web Start 1
2011. 9. 20. 11:45

Java Web Start

자바 웹스타트는 애플리케이션을 실행 하기 위한 기본적인 툴로, 웹브라우저를 사용 혹은 JNLP(java network launching protocol) 파일을 통해 애플리케이션을 사용자에 다운로드해 실행 할 수 있다. 이를 통해 배포, 유지보수, 업그레이드 작업을 수월하게 처리할 수 있다. Java로 작성된 많은 애플리케이션을 웹을 통해 배포, 실행 등을 할 수 있는 환경이 java web start 기술이다.

 

Java Web Start 특징

 

  • From a Web browser by clicking on a link.
  • From desktop icons or the Start Menu.
  • From the Java Cache Viewer

 

Java Web Start Software and the JCP

Java Web Start software provides a flexible and robust deployment solution for Java technology-based applications based on the Java Community Process program (JCP). The technology is being developed through the JCP program as JSR-56: The Java Network Launching Protocol & API (JNLP), which provides a browser-independent architecture for deploying Java 2 technology-based applications to the client desktop. You can download the Java Web Start specification.

 

Java Web Start technology works with any browser and any Web server. Each application developed for use with the Java Web Start software specifies which version of the Java 2 platform it requires, e.g., version 1.4 or 1.5, and each application runs on a dedicated Java Virtual Machine (JVM).

 

Auto-download of Software from java.sun.com

A main feature of the Java Network Launching Protocol and API technology is the ability to automatically download and install Java Runtime Environments onto the users machine.

Because the Java Web Start Java Runtime Environment installer uses Verisign certificates, the autodownload from http://java.sun.com/products/autodl/j2se works only if the client machine has version 1.3 or later of the Java Runtime Environment installed.

 

 

How to Request a Specific Version of the Java Runtime Environment

<j2se/>엘리먼트를 이용해 JRE 버전을 구분해 줄 수 있다. Currently, there are three different platforms supported: 1.2, 1.3, 1.4, and 1.5. For example:
j2se version="1.4 1.3+"
j2se version="1.4"

 

예제) j2se version="1.4.2*" href="http://java.sun.com/products/autodl/j2se"

The vendor-specific URL for Sun's JREs are: http://java.sun.com/products/autodl/j2se.

In the above example, a product version that has 1.4.2 as a prefix is requested, e.g., 1.4.2, 1.4.2_02, 1.4.2_04 would match.

 

 

<resources os=""/>는 OS별 library를 구분해 읽을 수 있다.

 

  1. <resources>
            <j2se      version="1.4+"/>
            <jar       href="trayicon.jar"/>
        </resources>
        <resources os="Windows">
            <jar       href="windows/jdic.jar"/>
            <nativelib href="windows/jdic-native.jar"/>
        </resources>
        <resources os="SunOS" arch="sparc">
            <jar       href="solaris_sparc/jdic.jar"/>
            <nativelib href="solaris_sparc/jdic-native.jar"/>
        </resources>
        <resources os="Linux">
            <jar       href="linux/jdic.jar"/>
            <nativelib href="linux/jdic-native.jar"/>
    </resources>

 

 

Java web start 애플리케이션 데모

 

demonstration applications

 

Creating Your First Program

Web Start 기술을 이용하기 위해서 특별한 애플리케이션을 개발하는 것이 아니고, java 기반 애플리케이션에 JNLP를 이용해 배포하는 것이다.

개략 다음과 같은 절차를 통해 java web start를 운영할 수 있다.

 

Library

Web Start 개발에 필요한 library로는 JRE에 포함된 {JRE}/lib/javaws.jar 이다.

절차
  1. Application 개발
  2. jar 패키징 혹은 singning jar
  3. 배포용 JNLP 개발
  4. Web Server Setup
  5. Web page link

 

1. 예제 애플리케이션
  1. import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    public class TheTime {
    public static void main(String args[]) {
    JFrame frame = new JFrame("Time Check");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel();
    Container content = frame.getContentPane();
    content.add(label, BorderLayout.CENTER);
    String message = "missing";
    BufferedReader reader = null;
    try {
    Socket socket = new Socket("time.nist.gov", 13);
    InputStream is = socket.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    reader = new BufferedReader(isr);
    reader.readLine(); // skip blank line
    message = reader.readLine();
    } catch (MalformedURLException e) {
    System.err.println("Malformed: " + e);
    } catch (IOException e) {
    System.err.println("I/O Exception: " + e);
    } finally {
    if (reader != null) {
    try {
    reader.close();
    } catch (IOException ignored) {
    }
    }
    }
    label.setText(message);
    frame.pack();
    frame.show();
    }
    }

 

2. jar singning

애플리케이션 클래스와 필요한 라이브러리를 jar로 패키징을 하고, 필요하다면 key를 생성해 singning을 처리한 후에 배포용 명세서를 JNLP 형식으로 작성한다.

JSDK에 포함된, jarsigner 를 이용해서 jar 파일을 singning해야 한다.

 

  1. First, create the JAR file:
    jar cf JNLPTime.jar TheTime.class
  2. Second, create a key in the keystore (or use one you already have). You'll be prompted for information like first name and last. You should at least fill in that information.
    keytool -genkey -keystore myKeys -alias jdc
  3. Third, sign the JAR. Be sure to remember your password from the previous step.
    jarsigner -keystore myKeys JNLPTime.jar jdc

 

3. JNLP 개발

 

1) jnlp 실행 위치: <jnlp spec="1.0+" codebase="file:///c:/jdc/jnlp/">

2) 로칼에서 실행 가능: <offline-allowed/>

3) 보안 인증, singing없이 실행 허가: 

<security>
<j2ee-application-client-permissions/>
</security>

4) 실행 클래스: resouce로 지정한 jar 파일에 있는 main-class가 실행이 된다.

<resources>
<j2se version="1.2+" />
<jar href="/developer/technicalArticles/Programming/jnlp/JNLPTime.jar"/>
</resources>
<application-desc main-class="TheTime" />
TheTime JNLP file
  1. <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="file:///c:/jdc/jnlp/">
    <information>
    <title>Time Check</title>
    <vendor>Java Developer Connection</vendor>
    <homepage href="/jdc" />
    <description>Demonstration of JNLP</description>
    </information>
    <offline-allowed/>
    <security>
    <j2ee-application-client-permissions/>
    </security>
    <resources>
    <j2se version="1.2+" />
    <jar href="/developer/technicalArticles/Programming/jnlp/JNLPTime.jar"/>
    </resources>
    <application-desc main-class="TheTime" />
    </jnlp>
4. Web Server Setup

1) Web Server에 MIME 타입 추가

  1. application/x-java-jnlp-file JNLP

2) 최신 버전의 Tomcat에는 포함되어 있고, 아래와 같은 구성을 web.xml에서 확인 가능하다.

  1. <mime-mapping>
    
    <extension>jnlp</extension>
    <mime-type>application/x-java-jnlp-file</mime-type> </mime-mapping>

JNLP API

JNLP가 제공하는 untrusted 클라이언트에서의 API를 이용하면 프린트, 로칼 파일 접근 등의 작업을 수행 할 수 있다.

Class/InterfaceDescription
BasicService Permits display of document in the user's browser.
ClipboardService Permits access to the system clipboard
DownloadService Used for cache control of local resources.
DownloadServiceListener Used to monitor progress of downloads.
ExtensionInstallerService Used to communicate with the JNLP client.
FileContents Provides read-write access to a file's contents.
FileOpenService Permits prompting of filename input for opening.
FileSaveService Permits prompting of filename input for saving.
JNLPRandomAccessFile Provides random read-write access to a file's contents.
PersistenceService Permits local storage of information on the client.
PrintService Permits access to printer.
ServiceManager Permits lookup of JNLP services.
ServiceManagerStub Describes how to lookup JNLP services.
UnavailableServiceException Thrown with lookup of non-existent or Unavailable service.
JNLP API 활용

Ant를 이용한 JNLP 패키징

Web Start application을 ANT를 이용해 singing과 packaging 및 배포를 할 수 있다.

Java WebStart와 SWT 배포

전통적인 자바 애플리케이션과는 달리, SWT 애플리케이션은 애플리케이션이 작동하기 전에 OS 스팩의 라이브러리들이 로딩되어야 합니다. 이러한 라이브러리들을 지속적으로 전개 및 관리해야 한다는 것은 쉽지 않지만 Sun의 Java Web Start가 도움이 됩니다. SWT와 Java Web Start가 결합하면 클라이언트 측 자바 애플리케이션 구축하는 데에 훌륭한 툴이 됩니다.

관련 자료

참조: http://java.sun.com/developer/technicalArticles/Programming/jnlp/index.html

JSR 56 - Java Network Launching Protocol and API specification

Java Web Start Developer Guide