Java:更新 jar 文件时加载类
我的 Java 程序在运行时动态加载类。所有类都位于同一个罐子中。
部署新的 jar 文件后,复制 jar 文件时有时会出现错误(NoClassDefFoundError 等)。当然,下次运行该程序时,这种情况就会消失。有没有办法预加载类,以便我的程序在更新 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使加载了所有类,您仍然可能会从资源中收到错误。
如果可能的话,我建议部署到不同的位置。或者,如果您可以管理类加载,请将 jar 复制到临时文件(例如,对于 http URL 会自动完成)或内存中。
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.