This tutorial is an update of How to deploy Java Web Start Applications on JBoss tested on JBoss EAP 6 and WildFly.

I have decided to update the older tutorial as a few changes are needed to run Java Web Start applications on newer versions of the application server. First of all, we will create a Web application named DemoWS. Within this application we will place at firstset up the Java Web Start configuration file. This file, placed at the root of the Web application, contains a description of the components and libraries needed to run the Java Web Start application.

Here is sample.jnlp :

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
      codebase="http://localhost:8080/DemoWS/" href="/sample.jnlp">
   <information>
      <title>Sample JWS application</title>
      <vendor>JBoss tutorials</vendor>
      <description>JWS on JBoss Demo</description>
      <homepage href="http://java.sun.com/docs/books/tutorial/deployment/webstart/running.html"/>
      <description kind="short">Example JWS application</description>
      <offline-allowed/>
   </information>
   <resources>     
       <jar href="/classes.jar"/>   
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
   </resources>
   <application-desc main-class="com.sample.MainClass"/>
</jnlp>

 The application classes are packaged into the JAR file named "classes.jar" and the Main class, com.sample.MainClass follows here:

package com.sample;

import java.awt.*;
import javax.swing.*;
import java.net.*;
import javax.jnlp.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MainClass {
  static BasicService basicService = null;
  static JFrame frame;
  public static void main(String args[]) {
    frame = new JFrame("Hello World Java Web start");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel();
    Container content = frame.getContentPane();
    content.add(label, BorderLayout.CENTER);
    String message = "Demo Java Web start";
    
    label.setText(message);

    try {
      basicService = (BasicService)
        ServiceManager.lookup("javax.jnlp.BasicService");
    } catch (UnavailableServiceException e) {
      System.err.println("Lookup failed: " + e);
    }

    JButton button = new JButton("Click me");

    ActionListener listener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        try {
        	JOptionPane.showMessageDialog(frame, "Hello from Java Web start");
        } catch (Exception ignored) {
        }
      }
    };

    button.addActionListener(listener);

    content.add(button, BorderLayout.SOUTH);
    frame.pack();
    frame.show();
  }
}

Finally, we need to package the Java Web Start libraries in the WEB-INF/lib folder of your application. These libraries are distributed as part of Java Client Downloads, which are available here.

In order to launch our application, we will include an index.html page that contains a link to the Java Web start application:

<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head><title>Demo Test of Java Web Start</title></head>
<body>
<center><a href="/sample.jnlp">Launch JWS</a></center>
</body>

That's all. The expected structure of your Web application follows here:

java web start jboss wildfly

Deploy your application on WildFly / JBoss EAP and test is with http://localhost:8080/DemoWS

Download the DemoWS application used in this example from here.

0
0
0
s2smodern