views:

114

answers:

1

My Java program loads classes dynamically at runtime. All classes are located in the same jar.

After deploying a new jar file, I sometimes get errors while the jar file is copying (NoClassDefFoundError etc.). This goes away the next time I run the program of course. Is there a way to preload classes so that my program is not affected when updating the jar?

I guess I could create instances of all classes and then clone() them, but perhaps there's a better way?

+1  A: 

Even if you load all the classes, you may still get errors from resources.

I suggest deploying to a different location if at all possible. Alternatively, if you can manager the class loading, copy the jar to a temporary file (which is automatically done for http URLs, for instance) or into memory.

Tom Hawtin - tackline