Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JNLP and Web Start and the fly likes lazy download a dependent library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "lazy download a dependent library" Watch "lazy download a dependent library" New topic
Author

lazy download a dependent library

Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

My application uses the Colt library, but it's not something that the program needs at start. It is a great candidate for a lazy download as I can check if it exists before running that particular task. However, will my program run if the library is missing? I have a couple imports, like "import cern.colt.matrix.impl.SparseDoubleMatrix2D;" Again, not anything that I need right away when the program runs, but it's a class used in the program. Can I use a library like this in a lazy way? Do I need to do anything specific in the code to trick it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's possible to specify jar files to be downloaded lazily in JNLP, yes. That's just a configuration option and you don't need to do anything in your code to help JNLP do its job. All that happens is that when your code attempts to load a class from that jar file, then JNLP downloads the jar file and loads the class from it.

But if the jar file is missing, and JNLP can't download it, then of course your program is going to crash when it tries to load a class from it.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

So does lazy download only download it if you call it in program? I assumed it would download it regardless, just that it didn't have to download it right away before it started the program.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Let me put it this way: based on the ordinary meanings of the terms, an "eager" download would take place as soon as possible, i.e. when the application starts, and a "lazy" download would take place as late as possible, i.e. not until the application asks for it.

And for jars, the application would "ask for" a jar simply by trying to load a class which is in that jar.

Why are you asking this question? Are you having problems running something, or are you seeing unexpected behaviour, or are you just unfamiliar with the terminology?
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I'm not running into errors, haven't used lazy yet. My goal is to minimize the download size off the application before the user can start using it. I've been able to separate my biggest image and sound files into their own jar. Their existence is optional and only enhance the program, so I wanted to set them as lazy. I thought jws would download all the eager ones first as they're required and then launch the program, while continuing to download the lazy ones in the background. Once I detect the existence of a lazy jar, I planned to enable those features.

I'm very new to jws and the terms. Am I incorrect in my understanding? Is there an easy way to request them once the program starts. I want them all downloaded, it's just some can wait for the trade of a fast download and start time for the user.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The terms mean simply what they normally mean. And is there a simple way to request lazily-downloaded jars? No, it's not as complicated as that. You don't "request" them specifically. All you do is to attempt to use something in them in the normal way and JNLP will download those jars as necessary. In other words you write your code normally without paying any attention to when JNLP is going to download the jar files.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I think I understand, sort of.. But if they are not downloaded yet, why wouldn't you get an error. Or do you get an error and you just ignore it? Or does it just sit there spinning circles trying to download 50MB of stuff? If it was a small download, why bother with lazy. Seems that I should attempt to access them all soon as the program starts to get them all downloading. Would something like this work.. getClass().getClassLoader().getResource("resources_sounds") to get it to download "resource_sounds.jar"
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yeah, for sure if you declare a 50-MB jar to be "lazy download" then it's going to sit there spinning its wheels as soon as you ask for anything that's in that jar. But on the other hand if you don't declare it "lazy" then it's going to be downloaded as part of the application startup, so the wheel-spinning happens at the beginning.
Jeff Gent wrote:If it was a small download, why bother with lazy.

Yes, I agree with that. You'd only want lazy downloading for a large jar which would make startup too slow if it was eagerly downloaded.
Jeff Gent wrote:Would something like this work.. getClass().getClassLoader().getResource("resources_sounds") to get it to download "resource_sounds.jar"

This is now the fourth time I've tried to explain this... You don't "get it to download a jar" in your code. Your code is (or should be) completely ignorant of what's in what jar. All you have to do is to write your code as if all of the jars in your classpath are accessible. It's then up to your configuration when those jars get downloaded to the client.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

Ya, guess it just seems like a stupid (and illogical) way to do it to me. It's only good for small downloads, and if it was a small download, then why not just do it at the beginning and be done with it. Guess it was just never made to allow for larger downloads in the background. What I thought was a cool feature seems worthless. Oh well.. guess I'll just see how it works out.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yup, I agree with you there, I don't think there's much use for lazy initialization. Especially in these days when most people have pretty big and fast pipes connecting them to the internet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lazy download a dependent library