简体   繁体   English

“ NoClassDefFoundError:javax / inject / Provider”即使包含javax.inject依赖项

[英]“NoClassDefFoundError: javax/inject/Provider” even with javax.inject dependency included

After upgrading some Glassfish/Grizzly dependencies (in order to be compatible with the latest version of Azure's SDK IOT device client), I started getting an error because com.google.common.EventBus no longer existed. 升级了某些Glassfish / Grizzly依赖关系(为了与Azure的最新版本的SDK IOT设备客户端兼容)之后,由于com.google.common.EventBus不再存在,我开始收到错误消息。 Adding the dependency: 添加依赖项:

<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>15.0</version>
</dependency>

fixed that, and it was able to run locally in IntelliJ. 修复了该问题,使其能够在IntelliJ中本地运行。 However, when I deployed the .deb file that was compiled to a Raspberry Pi, it started producing the error: 但是,当我部署已编译到Raspberry Pi的.deb文件时,它开始产生错误:

java.lang.NoClassDefFoundError: javax/inject/Provider at com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.jav a:81) at com.google.inject.Key.(Key.java:119) at com.google.inject.Key.get(Key.java:212) at com.google.inject.spi.Elements$RecordingBinder.bind(Elements.java:262 ) at com.google.inject.internal.InjectorShell$RootModule.configure(InjectorShell.java:276) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223) at com.google.inject.spi.Elements.getElements(Elements.java:101) at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103) at com.google.inject.Guice.createInjector(Guice.java:95) at com.google.inject.Guice.createInjector(Guice.java:72) at com.google.inject.Guice.createInjector(Guice.java:62) at com.infusion.empm.Main.main(Main.java:32) Caused by: java.lang.ClassNotFoundException: javax.inject.Provider at java.net.URLClas java.lang.NoClassDefFoundError:com上com.google.inject.Key。(Key.java:119)处com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.jav a:81)处的com.google.inject.internal.Morejavas / inject / Provider。 com.google.inject.spi.Elements $ RecordingBinder.bind(Elements.java:262)的google.inject.Key.get(Key.java:212)com.google.inject.internal.InjectorShell $ RootModule.configure( com.google.inject.spi.Elements $ RecordingBinder.install(Elements.java:223)的com.google.inject.spi.Elements.getElements(Elements.java:101)的InjectorShell.java:276) com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)上的.inject.internal.InjectorShell $ Builder.build(InjectorShell.java:133)com.google.inject.Guice.createInjector(Guice.java) :95),位于com.google.inject.Guice.createInjector(Guice.java:72),位于com.google.inject.Guice.createInjector(Guice.java:62),位于com.infusion.empm.Main.main(Main。 java:32)原因:java.lang.ClassNotFoundException:java.net.URLClas上的javax.inject.Provider sLoader$1.run(URLClassLoader.java:366) sLoader $ 1.run(URLClassLoader.java:366)

I read in a number of places that adding the dependency 我在很多地方都读到添加了依赖项

<dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
</dependency>

is supposed to fix that (I already had the guice & javax-servlet-api dependencies referenced here ), but it had no effect. 应该可以解决这个问题(我已经在这里引用了guice和javax-servlet-api依赖项),但是没有任何效果。 When I do so, the result is two javax.inject jars (the other one being generated would seem to explain why I didn't need to explicitly add version 1 to get it to run locally): 当我这样做时,结果是两个javax.inject jars(另一个生成的jar似乎可以解释为什么我不需要显式添加版本1使其在本地运行):

javax.inject-2.5.0-b42.jar javax.inject-2.5.0-b42.jar

javax.inject-1.jar javax.inject-1.jar

Someone else here used exclusions when they had those two jars, but even when I change my hk2 dependency accordingly, both jars are still present. 这里的其他人在拥有这两个jar时使用了排除项,但是即使我相应地更改了hk2依赖关系,两个jar仍然存在。 I've also heard that adding javax.ws.rs-api is supposed to help, but that was already there. 我还听说添加javax.ws.rs-api应该会有所帮助,但这已经存在。 The imports in the Java code refer directly to com.google.inject.Provider, so I don't think there's any need to call guicify to convert a JSR-330 provider to a Guice one. Java代码中的导入直接引用com.google.inject.Provider,因此我认为不需要调用guicify将JSR-330提供程序转换为Guice提供商。 Replacing every "com.google.inject" import in the local code with "java.inject" results in the same exact behavior, so it must be a dependency referencing google's code, which is in turn failing to find javax. 用“ java.inject”替换本地代码中的每个“ com.google.inject”导入都会导致相同的确切行为,因此它必须是引用Google代码的依赖项,从而无法找到javax。

事实证明,原因是Pi上的脚本在类路径中对jar进行了硬编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM