简体   繁体   中英

connection refused exception when trying to run a jar via web start

I am getting the following exception when trying to run my jar through java web start:

com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://localhost   /ValidatorWEB/validator.jnlp
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)

This is the wrapped exception:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)

Here is my .jnlp file:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://localhost/ValidatorWEB/" 
href="validator.jnlp">
<information>
    <title>Validator</title>
    <vendor>My Company</vendor>
</information>
<resources>
    <!-- Application Resources -->
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="WEB-INF/lib/validator.jar" main="true" />

</resources>
<application-desc
     name="Validator"
     main-class="webstartComponentArch.DynamicTreeApplication"
     width="300"
     height="300">
 </application-desc>
 <update check="background"/>

I am deploying the whole thing as a simple WAR to glassfish v2.1 on my local machine . The validator.jar is located in WEB-INF/lib and the jnlp and jsp page I am accessing the jnlp from is at the root of the ValidatorWEB folder.

Googling hasn't helped. I have tried turning my firewall off and it still does the same thing. I have the appropriate Mime-type set in Glassfish. Is there something else I'm forgetting to do?

You do know what http://localhost actually points to? It points to the web server which is running at localhost at port 80. Localhost == 127.0.0.1 == local machine.

As Webstart aka JNLP apps runs at the client machine, it will try to connect the web server at the same (local) machine. You don't want to do that. Change the URL to point to the actual web server at the server machine where your webapp runs and where JNLP is to be downloaded from.

So I figured it out. The problem was where I am specifying the base url:

<jnlp spec="1.0+" codebase="http://localhost/ValidatorWEB/" href="validator.jnlp">

When I deployed to Glassfish, the url that I would access the web application through is actually:

http://localhost:8080/ValidatorWEB/

I had to change my codebase to read:

<jnlp spec="1.0+" codebase="http://localhost:8080/ValidatorWEB/" href="validator.jnlp">

This is something I will definitely have to keep in mind when deploying to a remote server.

Thanks for all of the input!

The spaces after localhost make me suspicious - is there a chance you've defined the hostname with trailing spaces somewhere and web start isn't having any of it?

Also, have you tried simply wget ting (or similar) the listed jnlp URL? The response from the request will let you see what's happening when Java makes the same request.

我不知道它是否相关但在给出资源jar的地址时,我不会使用“WEB-ıNF/ lib”,客户端机器无法看到web-inf内部,你应该把那个jar放在web应用程序里面而不是web-inf里面。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM