Category Archives: Java Web Start

Java Web Start Application fails: connection refused exception when trying to run a jar via Java web start

I wrote my first Java Web Start application. Here as follows,

Step 1: My simple Hello World Swing java program

com.saravanansivaji.swing.HelloWorldSwing.java


package com.saravanansivaji.swing;

import java.awt.EventQueue;
import javax.swing.JFrame;

public class HelloWorldSwing extends JFrame {

public HelloWorldSwing() {

setTitle("Hello World example");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
HelloWorldSwing ex = new HelloWorldSwing();
ex.setVisible(true);
}
});
}
}

Step 2: I packed this as executable JAR file, myswing.jar

Step 3: Created a web application folder “apps” under Tomcat Server web application directory “webapps”.

E:\J2EE\apache-tomcat-6.0.18\webapps\apps

Step 4: Created a JNLP (Java Network Launch Protocol) file in the web folder “apps”, myswing.jnlp,

<?xml version=”1.0″ encoding=”utf-8″?>

<jnlp spec=”0.2 1.0″
codebase=”http://localhost:8081/apps&#8221;
href=”myswing.jnlp”>

<information>
<title>Welcome to Swing World</title>
<vendor>Saravanan Sivaji</vendor>
<homepage href=”index.html”/>
<description>Hello Swing World</description>
<icon href=”saravanansivaji.JPEG”/>
<offline-allowed/>
</information>

<resources>
<j2se version=”1.5+”/>
<jar href=”myswing.jar”/>
</resources>

<application-desc main-class=”com.saravanansivaji.swing.HelloWorldSwing”/>

</jnlp>

Step 5: Create an index page that invokes JNLP file

index.html

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<a href=”myswing.jnlp”>Run Swing Master</a>
</BODY>
</HTML>

So finally, my tomcat web folder “apps” contains the following files
1) a JAR file to launch
2) a JNLP file to invoke JAR
3) a index.html file to invoke JNLP file

Now running the tomcat web server and hitting the browser with URL

http://localhost:8080/apps/

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequest(Unknown Source)
at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

The issue occurred, my tomcat web server was running on 8081 port. But I had hit on localhost:8080 port.

Java web start application was launched the HelloWorldSwing component successfully.

Happy ending 🙂

Advertisements