AnonCow
AnonCow

Reputation: 1

Java: Load class while jar-file is updated

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?

Upvotes: 0

Views: 546

Answers (1)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

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.

Upvotes: 1

Related Questions