gpt4 book ai didi

java - 无法从在 Tomcat 中运行的 Guava r08 加载类。无法从源代码编译。缺少 javax.annotations

转载 作者:行者123 更新时间:2023-11-30 06:35:24 24 4
gpt4 key购买 nike

我正在尝试在我的学习 JSF 应用程序中使用 RichFaces。我已经使用

设置了 Maven
https://repository.jboss.org/nexus/content/groups/public-jboss/

我已经包含了依赖项

    <dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-api</artifactId>
<version>4.0.0.Final</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-api</artifactId>
<version>4.0.0.Final</version>
<type>pom</type>
<scope>compile</scope>
</dependency>

这已经获取了 guava-r08.jar。

当我尝试在 Tomcat7 中运行该项目时,我看到了很多类加载异常 - 无法加载我可以看到存在于 guava-r08.jar 以及 sac-1.3 和 cssparser-0.9.5 中的类。

如果我尝试改用源代码——从 guava-r09 获取源代码——Eclipse 告诉我它找不到 javax.annotation.Nullable 等类。问题是我也不能!

我在哪里可以找到这些类,或者我从一开始就采取了错误的方法?

谢谢

  • 理查德

最佳答案

RichFaces 依赖项的 Maven 配置

Tomcat 无法加载这些类,因为 RichFaces 对 Guava 的依赖具有运行时范围。与 compile 范围相反,这些依赖项在编译时不会添加到类路径中。您必须自己包含它们。

为此,您应该包括 richfaces-bom在你的 POM 的依赖管理部分,如解释的那样 in this JBoss wiki article .这将包括 Guava 和 RichFaces 可能需要的所有其他必需的依赖项。

这是“ Material list ”(BOM) 模式。 The JBoss wiki比我更好地解释了这种模式,并链接到有关该主题的其他文章。


javax.annotation.Nullable Guava 源代码中的警告

这些发生是因为 Guava 使用 JSR 305 annotations .使用 Guava 时不需要依赖 JSR 305 jar,因为注释不需要在编译后出现在类路径中。当然,如果您想在代码中使用 @Nullable 和其他此类注释(您绝对应该这样做),则需要添加 dependency on the JSR 305 jar。 .

关于java - 无法从在 Tomcat 中运行的 Guava r08 加载类。无法从源代码编译。缺少 javax.annotations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6113054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com