开发者

Java: Load class while jar-file is updated

开发者 https://www.devze.com 2022-12-16 15:45 出处:网络
My Java program loads classes dynamically at runtime. All开发者_如何学运维 classes are located in the same jar.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消