Eclipse Maven Web 应用程序 - 不能再在服务器上运行

Posted

技术标签:

【中文标题】Eclipse Maven Web 应用程序 - 不能再在服务器上运行【英文标题】:Eclipse Maven web application - can not run on server anymore 【发布时间】:2011-02-08 03:24:01 【问题描述】:

我有一个 maven eclipse webapp 项目,我可以右键单击并“在服务器上运行”,它将部署在 tomcat 上。我最近做了一个“maven -> 更新项目配置”,现在我不能将项目作为 web 应用程序部署和运行。有没有人见过这个?来自 tomcat 的唯一输出如下 - 它甚至看起来不像是在尝试部署应用程序。

Apr 14, 2010 3:58:54 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Apr 14, 2010 3:58:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.j2ee.server:taac-web' did not find a matching property.
Apr 14, 2010 3:58:54 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 14, 2010 3:58:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 402 ms
Apr 14, 2010 3:58:54 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 14, 2010 3:58:54 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Apr 14, 2010 3:58:54 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 14, 2010 3:58:54 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 14, 2010 3:58:54 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/14  config=null
Apr 14, 2010 3:58:54 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 247 ms

POM 仍设置为 WAR,但在清理项目后,我现在得到了作为 Maven 依赖项包含的库的 ClassNotFoundExceptions:

SEVERE: Error configuring application listener of class org.springframework.security.web.session.HttpSessionEventPublisher
java.lang.ClassNotFoundException: org.springframework.security.web.session.HttpSessionEventPublisher

这是我的 POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cable.wuntee.neto.nse</groupId>
  <artifactId>taac-web</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>taac-web JEE5 Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

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

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

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.16</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>1.3.0.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap</artifactId>
        <version>1.3.0.RELEASE</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.0.2.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-ldap</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-cada</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.cable.wuntee.neto.nse</groupId>
        <artifactId>wuntee.neto.nse-sams</artifactId>
        <version>2.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.0.1.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
    <finalName>taac-web</finalName>
  </build>
</project>

【问题讨论】:

【参考方案1】:

我经常遇到这个问题,快速解决方法是:

右键项目 -> Maven -> 更新项目... Eclipse Servers 选项卡:停止服务器,右键单击 Tomcat v# -> Clean... -> OK

以下是我用来查看 Eclipse 在运行 tomcat 时实际部署的故障排除步骤。这是目前的火星和霓虹灯。 (这些步骤假设您使用“在服务器上运行...”至少运行了一次项目)

    调出在tomcat上运行项目的设置: 右键项目 -> 运行方式 -> 运行配置... 转到参数选项卡并查看 VM 参数,您将看到如下内容: 查找-Dwtp.deploy 的值。对我来说是

D:\code\workspaceNeon\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps

    该目录包含标准的 webapp 部署结构。在您的操作系统文件资源管理器中打开该目录并检查其内容。当我查看我的 WEB-INF/lib 时,我发现我的大部分依赖项都丢失了 完成后请务必退出该目录,否则 eclipse 在尝试修改/更新它时会出错

现在是解决问题的时候了。让我们看看应该部署什么 Eclipse:

    为您的项目打开部署程序集设置:

    右键项目->属性->部署程序集

      Maven 依赖项是上面的关键项。 如果缺少,请关闭对话框并执行 Maven 更新: 右键项目 -> Maven -> 更新项目...

      现在我们已经进行了更新,让我们手动清除服务器工作目录并重新发布。这可能并不总是必要的,但它是确保部署程序集中显示的内容与实际部署的内容之间保持同步的好方法:

      在 Eclipse 中转到“服务器”选项卡。如果您在当前的 Eclipse 布局中没有看到它,请执行 窗口菜单 -> 显示视图 -> 其他.. -> 搜索“服务器” 右键单击 Tomcat v#... 并选择“清理...”。在确认对话框中单击确定 右键单击 Tomcat v#... 并选择“发布” 启动服务器并进行测试。如果仍有问题,请返回 wtp.deploy 目录并检查以查看问题所在

祝你好运!

【讨论】:

【参考方案2】:

好的,我也为此苦苦挣扎。我认为没有太多明确的答案,有一段时间我会删除该项目并重新导入它,因为这样每次都可以。

今天我发现它在对项目运行 maven clean 后又开始工作了(例如,从命令行执行 mvn clean)。尝试一下,看看它是否适合您。

这不等同于 eclipse clean,因为它只从目标目录中删除选定的几个文件夹,而不是全部。

【讨论】:

【参考方案3】:

我今天遇到了同样的问题,对我来说,在 eclipse 中重新安装 apache 并在之后重建/刷新项目会有所帮助

【讨论】:

【参考方案4】:

我在

上找到了答案

Tomcat & Spring Web - Class Not Found Exception org.springframework.web.context.ContextLoaderListener

当项目发布到服务器时,你需要将 Maven 依赖推送到服务器。

在项目资源管理器中右键单击您的 Web 项目 -> 选择“属性”。在项目属性下,选择“部署程序集”。

Deployment Assembly 属性页显示将由 Eclipse 作为组装工件发布到服务器的内容。您需要告诉 Eclipse 您也希望发布所有 Maven 依赖项。

为此,请单击“添加”按钮,然后选择“Java 构建路径条目”。单击下一步并选择 Maven 依赖项。这将在 Eclipse 将您的项目发布到 WST 服务器时将 Maven 依赖 JAR 文件发布到 lib 文件夹

【讨论】:

【参考方案5】:

在项目属性下,转到“构面”,按转换为某事,启用动态网络模块并按应用。

【讨论】:

【参考方案6】:

三种可能的解决方案。我已经使用了所有三个,具体取决于它是如何出错的。

    我通过从我的 POM 中删除 spring 安全依赖项解决了这个问题(我只有 spring-security-taglibs 和 spring-security-config 可以拉入我需要的所有其他内容),保存了 POM,让 Maven 来做东西,然后再次添加它们,让 Maven 再次获取依赖项并在 Eclipse 中重新启动服务器。当问题发生时,Eclipse 项目中的 Maven 依赖项目录似乎缺少 spring-security-web 工件(其中包含 org.springframework.security.web.session.HttpSessionEventPublisher)。对我来说,它只会在我重启电脑后启动 Eclipse 时发生,所以我假设它是 Windows (Vista) 并且 Eclipse M2Eclipse 插件在文件锁定或其他方面不能很好地发挥作用。

    替代解决方案(问题再次发生,以前的解决方案不起作用)。这一次,我从本地 maven 存储库(Eclipse Window->Preferences->Maven->User Settings 中的那个)中删除了 org/springframework 目录。然后,更新 Maven 依赖项,哇,我们又来了。

    如果您已完成“Maven->更新项目配置”并且发生这种情况,很可能是因为您的“部署程序集”设置不包括 Maven 依赖项。转到项目-> 属性-> 部署程序集。检查 Maven 依赖项是否在其中,并具有 /WEB-INF/lib 的部署路径。如果没有,请单击添加并在 Java 构建路径选项下找到它。如果它不存在,那么您的构建路径也可能已损坏(尽管我从未发生过这种情况)。

【讨论】:

【参考方案7】:

替代解决方案(问题再次发生,以前的解决方案不起作用)。

这一次,我从本地 maven 存储库(Eclipse Window->Preferences->Maven->User Settings 中的那个)中删除了 org/springframework 目录。然后,更新 Maven 依赖项,哇,我们又来了。

【讨论】:

【参考方案8】:

我遇到了您在 WAR 项目中遇到的奇怪编译错误。由于某种原因,类路径以某种方式发生了更改,它忽略了我工作区中 WAR 所依赖的其他项目。

最终奏效的唯一解决方案是删除我的工作区,并在每个项目上删除 .classpath、.project 和 .settings。从一个新的工作区开始解决它。

我确实在 Maven WTP 错误跟踪器中找到了一个 bug 提到类似的东西,但我猜我没有得到足够的票来修复。

【讨论】:

【参考方案9】:

这些都没有帮助 - 我最终只是禁用了工作区解析,并在它们过时时处理安装工作区依赖项。

【讨论】:

【参考方案10】:

也许您每次意外将 &lt;packaging&gt;war 更改为其他内容。你能展示你的POM吗?

您能否确认您已安装 Maven WTP Integration for WTP(这不太可能,但也许您安装了最新版本的 M2Eclipse 没有这个额外的东西,不知何故,在您更新之前一切正常项目配置)?

【讨论】:

是的,已经安装了 Maven WTP - 只是尝试卸载并重新安装(没有帮助)。而且,是的,在我更新项目配置之前它就可以工作了……在下面的帖子中查看新的错误/pom also - 如果我打包项目,它会将所有 .jar 文件复制到 WEB-INF/libs 目录;如果我手动将它们放在 eclipse 项目中,它运行良好......不知道为什么 WTP 没有在 eclipse 中管理它...... @wuntee 您之前为“更新项目配置”做了哪些更改。您是否更改了某些版本? 向'main/resources'目录添加了一个文件...我从eclipse中删除了该项目,然后将其导入,它似乎已经解决了这个问题。不知道到底发生了什么。 @wuntee 很高兴它解决了。我会让你将此作为答案发布,并在完成后删除我的。

以上是关于Eclipse Maven Web 应用程序 - 不能再在服务器上运行的主要内容,如果未能解决你的问题,请参考以下文章

eclipse 创建maven web项目

eclipse中怎么创建maven web project

idea/eclipse下Maven工程集成web服务(tomcatjetty)

Eclipse Maven Web 应用程序 - 不能再在服务器上运行

eclipse 中创建maven web项目

eclipse 创建maven web项目