如何找出在编译时加载了哪个class?
How to find out which class is loaded at compile time?
我有一个项目有很多依赖关系,我在代码中的某处实现了一个 class,如下所示:
public class MyApp extends org.some.BaseClass
问题是,依赖项中有多个 jar 提供基础 class org.some.BaseClass
,其中一些包含我需要实现的特定抽象方法,其他则不需要。显然,编译器想要使用我不想实现的那些基础 classes 之一,它失败了:
[ERROR] MyApp is not abstract and does not override abstract method getSome() in org.some.BaseClass
现在,从这里:Find where java class is loaded from 我了解了 jvm opt -verbose:class
,它列出了所有正在加载的 classes 以及它从哪里加载它们。这似乎非常适合分析目的。但是,我猜想由于当时编译器仍在工作并且 classes 尚未完全加载,所以 org.some.BaseClass
的源代码未打印在输出中。编译器只是失败并且没有提及任何细节。
那么,我怎样才能找出 class 在编译时针对什么进行编译?对于有编译错误的文件,是否有另一个 jvm 标志打印与 verbose:class
相同的信息?
更新:
通过将 -verbose
添加到 javac 参数来解决。原来错误的 class 来自一个阴影 jar,它直接包含其依赖项中的所有 classes。 IDE 无法告诉我这件事,因为那个 jar 也是项目的一部分作为模块。
来自 javac
手册:
-verbose
- Verbose output. This includes information about each class loaded and each source file compiled.
我有一个项目有很多依赖关系,我在代码中的某处实现了一个 class,如下所示:
public class MyApp extends org.some.BaseClass
问题是,依赖项中有多个 jar 提供基础 class org.some.BaseClass
,其中一些包含我需要实现的特定抽象方法,其他则不需要。显然,编译器想要使用我不想实现的那些基础 classes 之一,它失败了:
[ERROR] MyApp is not abstract and does not override abstract method getSome() in org.some.BaseClass
现在,从这里:Find where java class is loaded from 我了解了 jvm opt -verbose:class
,它列出了所有正在加载的 classes 以及它从哪里加载它们。这似乎非常适合分析目的。但是,我猜想由于当时编译器仍在工作并且 classes 尚未完全加载,所以 org.some.BaseClass
的源代码未打印在输出中。编译器只是失败并且没有提及任何细节。
那么,我怎样才能找出 class 在编译时针对什么进行编译?对于有编译错误的文件,是否有另一个 jvm 标志打印与 verbose:class
相同的信息?
更新:
通过将 -verbose
添加到 javac 参数来解决。原来错误的 class 来自一个阴影 jar,它直接包含其依赖项中的所有 classes。 IDE 无法告诉我这件事,因为那个 jar 也是项目的一部分作为模块。
来自 javac
手册:
-verbose
- Verbose output. This includes information about each class loaded and each source file compiled.