在Eclipse 3.5中从Tomcat 6上运行Spring + Maven2项目时,ClassNotFoundException异常 [英] ClassNotFoundException when running a Spring + Maven2 project on Tomcat 6 from within Eclipse 3.5

查看:191
本文介绍了在Eclipse 3.5中从Tomcat 6上运行Spring + Maven2项目时,ClassNotFoundException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图从Eclipse中启动一个Web项目时,我得到:

When trying to launch a Web project from within Eclipse I get:


SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3877)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

当我切换到Fedora 12 x64时,项目开始失败。该项目以相同的配置工作在WinXP上。

Project started to fail when I switched to Fedora 12 x64. The project worked on WinXP with same configuration.

Google搜索结果发现,要发布的项目属性 - > Java EE模块依赖关系和检查Maven依赖关系框解决了这个问题。不幸的是,它没有为我工作。

Googling around I found posts claiming that going to Project Properties -> Java EE Module Dependencies and checking the Maven Dependencies box fixes the issue. Sadly it didn't worked for me.

我使用的是Spring 2.5.6,Maven2,Eclipse 3.5(使用m2e 0.10.0插件),Tomcat 6和Java 6在Fedora 12 x64上运行。

I'm using Spring 2.5.6, Maven2, Eclipse 3.5 (with the m2e 0.10.0 plugin), Tomcat 6 and Java 6 running on Fedora 12 x64.

有没有人看到这个问题?

Has anyone seen this problem?

我的.classpath文件

In case it helps here is my .classpath file


<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java"/>
    <classpathentry kind="src" output="target/classes" path="target/generated-sources/gpb"/>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>

    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>

    <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.iam.jdt.core.mavenClasspathContainer">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

更新:我在构建或运行项目时没有任何问题外面的Eclipse。

Update: I don't have any problems building or running the project outside Eclipse.

推荐答案

你似乎都有 Eclipse IAM M2Eclipse 您的的.classpath 。我会做一些清理:

You seem to have both Eclipse IAM and M2Eclipse stuff in your .classpath. I would do some cleanup:


  • 只使用这些插件之一(我建议使用M2Eclipse)。

  • 从Eclipse的工作空间中删除项目,删除 .classpath .project 并将项目导入为Maven项目再次。

  • Use only one of these plugin (I suggest using M2Eclipse).
  • Delete your project from Eclipse's workspace, delete the .classpath and .project and Import the project as a Maven project again.

更新:要使用M2Eclipse获取WTP支持,您需要安装 Maven来自m2eclipse的WTP集成其他更新站点: http://download.eclipse .org / m2e-wtp / releases / ,如下所示:

Update: To get WTP support with M2Eclipse, you need to install the Maven Integration for WTP from the m2eclipse Extras update site: http://download.eclipse.org/m2e-wtp/releases/ as illustrated below:

这篇关于在Eclipse 3.5中从Tomcat 6上运行Spring + Maven2项目时,ClassNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆