개요

Java 어플리케이션을 배포하는 새로운 방식인 JNLP 를 테스트 해 보도록 한다.

 

테스트 프로그램

<DayTime.java>

package net.cranix.daytime.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class DayTime {
    /**
     * DayTime 서버로부터 결과를 받아서 돌려주는 함수
     * @param server
     * @return
     * @throws IOException
     * @throws UnknownHostException
     */
    public String getRemoteTime(String server) throws UnknownHostException, IOException {
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;
        try {
            Socket sock = new Socket(server,13);
            br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            String line = null;
            while((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
        }
        finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString().trim();
    }

}

 

<MainFrame.java>

package net.cranix.daytime.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.cranix.daytime.model.DayTime;

public class MainFrame extends JFrame {
    private JLabel label = null;
    private JButton closeBtn = null;
    private JButton reloadBtn = null;
    private DayTime model = null;
    public MainFrame(DayTime model) {
        super();
        this.model = model;
        init();
        updateTime();
    }
    public void updateTime() {
        try {
            label.setText(model.getRemoteTime("time.nist.gov"));
            pack();
        } catch (UnknownHostException e) {
            JOptionPane.showMessageDialog(this, e);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(this, e);
        }
    }
    public void init() {
        // 이벤트 처리
        label = new JLabel("TimeLabel");
        reloadBtn = new JButton("Reload");
        reloadBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updateTime();
            }
        });
        closeBtn = new JButton("Close");
        closeBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                dispose();
            }
        });
        // 컴포넌트 배치
        JPanel btnPanel = new JPanel();
        btnPanel.add(reloadBtn,BorderLayout.EAST);
        btnPanel.add(closeBtn,BorderLayout.WEST);
        getContentPane().add(label,BorderLayout.CENTER);
        getContentPane().add(btnPanel,BorderLayout.SOUTH);
        // 프레임 설정
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("DayTime");
        setResizable(false);
    }
}

 

<Main.java>

package net.cranix.daytime;

import net.cranix.daytime.model.DayTime;
import net.cranix.daytime.view.MainFrame;

public class Main {
    public Main() {
        DayTime model = new DayTime();
        MainFrame view = new MainFrame(model);
        view.setVisible(true);

    }
    public static void main(String args[]) {
        new Main();
    }
}

 

 

JNLP XML 설정

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="file:///E:/cranix/workspace/DayTime">
    <information>
        <title>DayTime</title>
        <vendor>cranix</vendor>
        <homepage href="http://cranix.net" />
        <description>demo daytime</description>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.2+" />
        <jar href="DayTime.jar"/>
    </resources>
    <application-desc main-class="net.cranix.daytime.Main" />
</jnlp>

 

jar 파일 서명하기

keytool –genkey –keystore cranixKeystore –alias cranix

keytool –selfcert –alias cranix –keystore cranixKeystore

keytool –list –keystore cranixKeystore

jarsigner –keystore cranixKeystore DayTime.jar cranix

 

 

실행하기

생성한 jnlp 파일을 더블클릭

image

신고

'알짜정보 > Java' 카테고리의 다른 글

자바 힙덤프 뜨기  (69) 2012.12.18
JNLP 테스트  (36) 2010.02.14
JAVA 리눅스 IP 주소 알아내기  (38) 2008.12.02
apache 프로젝트의 commons-dbcp 를 이용하여 connection pool 만들기.  (42) 2008.08.15
java 에서 xmlrpc 사용하기  (38) 2008.07.13
annotation 주석?  (43) 2006.12.16
by cranix 2010.02.14 15:24
| 1 2 3 4 5 6 7 |