Lazy loading jar files for unsigned applet

  • Thread starter marek.scholaster
  • Start date
M

marek.scholaster

Hello,
I have an unsigned Java applet consisting of several jar files.
Currently all jar files are downloaded on applet's startup. Is there
any chance to download the jar files only when they are really needed?
Thank you for any hint.
Marek
 
Q

Qu0ll

Hello,
I have an unsigned Java applet consisting of several jar files.
Currently all jar files are downloaded on applet's startup. Is there
any chance to download the jar files only when they are really needed?
Thank you for any hint.

Are you sure that all the JARs are being downloaded on startup? In general,
a JAR is only downloaded when a class in that archive is accessed.
Therefore, to delay this until absolutely necessary you need to program
against an interface and then instantiate the required class using
Class.forName() when it is first accessed. You can even configure things so
that only the actual applet class is in one JAR which is downloaded on
startup and have all the other classes in other JARs that are only
downloaded as required.

If you have several JARs you can index them to speed up the process of
locating the required classes when required. Look at the documentation for
the jar command. I think it's jar -i.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
M

marek.scholaster

Hello,
I have an unsigned Java applet consisting of several jar files.
Currently all jar files are downloaded on applet's startup. Is there
any chance to download the jar files only when they are really needed?
Thank you for any hint.

Are you sure that all the JARs are being downloaded on startup?  In general,
a JAR is only downloaded when a class in that archive is accessed.
Therefore, to delay this until absolutely necessary you need to program
against an interface and then instantiate the required class using
Class.forName() when it is first accessed.  You can even configure things so
that only the actual applet class is in one JAR which is downloaded on
startup and have all the other classes in other JARs that are only
downloaded as required.

If you have several JARs you can index them to speed up the process of
locating the required classes when required.  Look at the documentation for
the jar command.  I think it's jar -i.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]

I'm using Fiddler to see what is downloading.
I tried Class.forName() but anyway the classloader needs to know where
to get the class from. Therefore I had to mention the jar in the
manifest and again the jar is downloaded on startup.
I will try Jar indexing.
Thanks, Marek
 
Q

Qu0ll

I'm using Fiddler to see what is downloading.
I tried Class.forName() but anyway the classloader needs to know where
to get the class from. Therefore I had to mention the jar in the
manifest and again the jar is downloaded on startup.
I will try Jar indexing.

If the JAR is downloading on startup it means you have declared an object of
that class somewhere in your code. Don't. Just refer to it using an
interface (which is in a *different* JAR) so that it doesn't need to get the
class definition until it is actually used.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
R

Roedy Green

I have an unsigned Java applet consisting of several jar files.
Currently all jar files are downloaded on applet's startup. Is there
any chance to download the jar files only when they are really needed?

deploy your applet with Java Web Start. Then you have control of how
each jar is loaded.

see http://mindprod.com/jgloss/javawebstart.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Think of the earth as a living organism that is being attacked by billions of bacteria whose numbers double every forty years. Either the host dies, or the virus dies, or both die."
~ Gore Vidal
 
A

Andrew Thompson

....

deploy your applet with Java Web Start. Then you have control of how
each jar is loaded.

Further, if the user has 1.6.0_10+, the applet can still
begin 'embedded' in the web page..

I do not believe* that there are any guarantees of lazy
downloading, if the applet is embedded in a web page
using the standard applet element (and is sandboxed).

* Later (1.5+?) JREs might behave niceley if using Jar
indexing, as suggested by Qu0ll.
 
Joined
Apr 29, 2009
Messages
1
Reaction score
0
You can use Utils4Swing

You could use the Utils4Swing library (fuin.org/utils4swing/javadoc/org/fuin/utils4swing/common/Utils4Swing.html) to add any JAR you like to the applet's classpath with the following statement:

Utils4Swing.addToClasspath(...);

This uses an little "hack" to add it to the classpath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top