Link to home
Start Free TrialLog in
Avatar of asimion
asimion

asked on

Java Web Start & JNLP

Hi everybody!

     I'm using an application with Java Web Start and, of course, I've created a JNLP file.
The problem is that my application use an external text file, and I don't know how to "tell" Java Web Start to download this file too, when I'm starting the application.

I guess the problem is in JNLP's configuration. I don't know how to configure this JNLP file to specify that I need an external resource for my application.

Can anyone help me ?

Thanx a lot.
Sam
Avatar of Ovi
Ovi

Why don't you put all files (the app and the txt) in a global .jar file ?
Hi..
Try this..

import javax.jnlp.*;
    ...

    DownloadService ds;

    try {
        ds = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService");
    } catch (UnavailableServiceException e) {
        ds = null;
    }

    if (ds != null) {

        try {
            // determine if a particular resource is cached
            URL url =
                    new URL("http://localhost\file location
            boolean cached = ds.isResourceCached(url, "1.0");
            // remove the resource from the cache
            if (cached) {
                ds.removeResource(url, "1.0");
            }
            // reload the resource into the cache
            DownloadServiceListener dsl = ds.getDefaultProgressWindow();
            ds.loadResource(url, "1.0", dsl);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

LGG

Avatar of asimion

ASKER

Hi LGG,

     I've tried your code but it doesn't seem to download the file. I don't receive any error but I don't get the file either. How can I know if the download was succesfully and how can I acces the downloade file ?
Avatar of Mick Barry
If you put the file in your jar then you can simply read it using:

InputStream in = ClassLoader.getSystemResourceAsStream("filename.txt");

// Read your file from input stream


Avatar of asimion

ASKER

I don't want to use the file inside the jar !
I now this way it's working, because the file will be downloaded by JavaWebStart. But I need the file outside the jar because will be modified very often, and I don't want to modify the whole jar every time.
Then you'll need to make it available somewhere for download, as far as I know Web Start doesn't support additional resources.
Will check for u.
Avatar of asimion

ASKER

The txt file is in the same directory with the jar file and the JNLP file on the server.

If I try to download the file like this :

http://servername/filename.txt with any browser, it's working!

So, that mean it's available for download...., isn't it ?
JNLP only supports specifying jars, images, and other jnlp's. So you'll need to jar your external text file for jnlp to grab it.

Something like this:

<resources>
  <jar href="http://abc.com/text.jar"/>
</resources>

Then use the standard getResource methods in your code to access your data.

If you need more info have a look at the JNLP spec.

That does mean its available for download.
Maybe you can ask Sey again to solve the problem.


Best Regards,   :)
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points NOT refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial