当以TestNG运行时,我遇到了简单打印程序的错误
[RemoteTestNG] detected TestNG version 7.0.1
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/google/inject/Stage
at org.testng.internal.Configuration.<init>(Configuration.java:33)
at org.testng.TestNG.init(TestNG.java:216)
at org.testng.TestNG.<init>(TestNG.java:200)
at org.testng.remote.AbstractRemoteTestNG.<init>(AbstractRemoteTestNG.java:17)
at org.testng.remote.support.RemoteTestNG6_12.<init>(RemoteTestNG6_12.java:18)
at org.testng.remote.support.RemoteTestNGFactory6_12.createRemoteTestNG(RemoteTestNGFactory6_12.java:16)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:67)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Stage
... 7 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.Stage
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
[使用类中的方法运行简单的打印程序时
[RemoteTestNG] detected TestNG version 7.0.1
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/google/inject/Stage
...暗示由于com/google/inject/Stage
中的NoClassDefFoundError而存在BootstrapMethodError。
根据testng 7.1.0 java.lang.ClassNotFoundException: com.google.inject.Stage中的讨论,@ krmahadevan提到7.0.0 pom中对guice的依赖性信息为:
<dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.1.0</version> <classifier>no_aop</classifier> <scope>provided</scope> </dependency>
与7.1.0 pom一样,guice的依赖信息是:
<dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.1.0</version> <classifier>no_aop</classifier> <scope>compile</scope> </dependency>
由于Guice是compile time dependencyTestNG,需要使Guice成为pom清单中的编译依赖项,或使jectorFactory延迟初始化。
解决方案通过以下Maven依赖关系通过合并Fixing a hard dependency on Guice Libraries解决了此问题:
<dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.1.1-SNAPSHOT</version> <scope>test</scope> <exclusions> <exclusion> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
此修复程序仅在16小时前合并(截至2010年3月10日),然后从“安装新软件”中重新安装testng插件将解决此问题。