【问题标题】:Error when deploying a JSP/Servlet project with maven on jboss6在 jboss6 上使用 maven 部署 JSP/Servlet 项目时出错
【发布时间】:2011-08-24 16:44:49
【问题描述】:

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 在 java.net.URLClassLoader$1.run(URLClassLoader.java:217) [:1.6.0_20] 在 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 的任何引用

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

请指教。 谢谢

【问题讨论】:

    标签: jsp jsf maven-2 jboss6.x


    【解决方案1】:

    我也遇到过同样的问题。你应该替换 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 的依赖设置为 provided 范围,因为 Web 容器提供了这些类。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-30
      • 1970-01-01
      • 2014-08-12
      • 2014-06-04
      • 2016-08-28
      • 2018-05-12
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多