本文介绍了ClassLoader:可能配置为使用惰性而不是静态解析吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了,它说的是分辨率

所以我的问题是我是否可以选择选择/强制使用 lazy 初始化?也许需要编写自定义类加载器?也许在启动时在类加载器中的ClassNotFoundException可能会被忽略?


我在 main 中有条件地创建了一个对象,实际发生,并且jar中缺少相应的类。但是 NoClassDefFound 甚至在 main 开始执行之前就被抛出。

解决方案

NoClassDefFoundError 错误:

与实例化所讨论类的实例无关的错误。因此,对于您的示例,如果外部类为该类型定义一个字段,就足够了。您的包含主类的类无法加载,因为它取决于在运行时类路径上不可用的类型。



如果有疑问,请仔细阅读您的import语句,并删除要动态加载的类的import )。然后尝试摆脱错误标记,而无需为该类再次添加导入。



)-我认为,此动态加载的类位于其他包中,因此需要导入。


I read JLS Chapter 12. Execution so it says about resolution

So my question is whether I can select to choose/force to use lazy intialization? Maybe it requires writing a custom class loader? Or maybe ClassNotFoundException in class loader at start up might be ignored?

I have a conditional creation of an Object in main which should never actually happen and that corresponding class is missing from jar. But NoClassDefFound is thrown even before main starts execution.

解决方案

The NoClassDefFoundError error:

The error not related to instantiating an instance of the class in question. So for your example, it may be enough, if the "outer" class defines a field for that type. Your class, that contains the main, can't be loaded, because it depends on a type that is not available on the classpath at runtime.

If in doubt, look through your import statements and remove the import) for the class that you want to load dynamically. Then try to get rid of the error markers without adding an import for that class again.

) - I assume, that this dynamically loaded class is in a different package and you need an import for it.

这篇关于ClassLoader:可能配置为使用惰性而不是静态解析吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 14:47