0

Maven依赖问题。

大家好,

这是参考我之前的帖子 Error with Jboss while deploying a jsp/servlet web app "com.sun.faces.config.ConfigureListener" Error

当我不通过 maven 构建并将项目导出为战争(我使用 Eclipse for J2EE)并通过其管理控制台将其部署到 Jboss6 时,它运行良好,而如果我使用 mvn clean install 通过 maven 构建并复制由 maven 构建的战争到我的 /deploy 目录(Jboss)我收到以下错误

2011-05-10 14:41:57,509 信息 [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) 部署,ctxPath=/UltimateSMS-1 2011-05-10 14:41:57,681 错误 [org .apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/UltimateSMS-1]] (HDScanner) 配置类 com.sun.faces.config.ConfigureListener 的应用程序侦听器时出错:java.lang.ClassNotFoundException : com.sun.faces.config.ConfigureListener at java.net.URLClassLoader$1.run(URLClassLoader.java:217) [:1.6.0_20] at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_20]在 java.net.URLClassLoader.findClass(URLClassLoader.java:205) [:1.6.0_20]

战争的部署失败了。

这是我的 pom 的一部分

    <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                    <version>2.5</version>
                    <type>jar</type>
                    <scope>compile</scope>
            </dependency>
            <dependency>
                    <groupId>jboss</groupId>
                    <artifactId>jboss-j2ee</artifactId>
                    <version>4.0.2</version>
                    <type>jar</type>
                    <scope>compile</scope>
            </dependency>
    <dependency>
                    <groupId>javax</groupId>
                    <artifactId>javaee-web-api</artifactId>
                    <version>6.0</version>
            </dependency>

在我的 web.xml 中没有配置一个 faces 侦听器并且它没有对 JSF 的任何引用

PS:我的项目是一个简单的 JSP/Servlet J2EE 项目,没有引用 JSF,所以我使用 JDK 1.6 和 Maven -> Apache Maven 3.0.3
我已经缩小了错误范围,我认为问题出在我的 pom.xml

请指教。谢谢

4

1 回答 1

4

我遇到过同样的问题。您应该替换为pom.xml

    <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <type>jar</type>
                <scope>compile</scope>
    </dependency>

和 :

    <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>6.0</version>
    </dependency>

经过 :

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

根据maven doc,您应该将 Servlet API 和相关 Java EE API 的依赖设置为提供的范围,因为 Web 容器提供了这些类。

提供 这很像编译,但表示您希望 JDK 或容器在运行时提供依赖项。例如,在为 Java Enterprise Edition 构建 Web 应用程序时,您可以将 Servlet API 和相关 Java EE API 的依赖设置为提供的范围,因为 Web 容器提供了这些类。此范围仅在编译和测试类路径上可用,并且不可传递。

于 2012-01-18T18:43:34.340 回答