运行 Spring 时出现 ClassNotFoundException Eclipse 3.5 中 Tomcat 6 上的 Maven2 项目

发布于 2024-08-28 05:08:02 字数 3371 浏览 6 评论 0原文

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


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 上运行,配置相同。

谷歌搜索后,我发现帖子声称要转到“项目属性 ->” Java EE 模块依赖项并选中 Maven 依赖项框可以修复该问题。遗憾的是它对我不起作用。

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

有人见过这个问题吗?

如果它有帮助,这里是我的 .classpath 文件


<?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 之外构建或运行该项目没有任何问题。

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)

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

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.

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?

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>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷爱 2024-09-04 05:08:02

您似乎同时拥有 Eclipse IAMM2Eclipse 内容在您的 .classpath 中。我会做一些清理:

  • 仅使用这些插件之一(我建议使用 M2Eclipse)。
  • 从 Eclipse 工作区中删除您的项目,删除 .classpath.project 并再次将项目导入为 Maven 项目。

更新:要获得 M2Eclipse 的 WTP 支持,您需要从 m2eclipse Extras 更新站点安装 Maven Integration for WTP: eclipse.org/m2e-wtp/releases/" rel="nofollow noreferrer">http://download.eclipse.org/m2e-wtp/releases/ 如下所示:

在此处输入图像描述

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

  • 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.

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:

enter image description here

悟红尘 2024-09-04 05:08:02

我有相同的症状但原因不同。我必须编辑我的 .classpath 文件。 maven 条目:

<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>

...缺少此处显示的属性标签。当我添加属性标签时,问题就消失了。我很好奇如何在 eclipse ui 中配置它。

I had the same symptom with a different cause. I had to edit my .classpath file. The maven entry:

<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>

...was lacking the attributes tag shown here. When I added the attributes tag the problem went away. I'm very curious how to configure that in the eclipse ui.

浪荡不羁 2024-09-04 05:08:02

请注意,安装 WTP 集成的步骤已更改。

请参阅:Eclipse Indigo/3.7 中的 Maven/Tomcat 项目

Note that the steps to install the WTP integration have changed.

See: Maven/Tomcat Projects In Eclipse Indigo/3.7

清风不识月 2024-09-04 05:08:02

时不时地面临同样的问题。

由于某些奇怪的原因,这个问题可以通过以下方式解决:

1)右键单击项目 Maven ->禁用Maven依赖项

2)鼠标右键单击项目Maven ->启用 Maven 依赖项

From time to time, face with same problem.

For some strange reason, this problem could be fixed this way

1) Right mouse click on project Maven -> Disable Maven Dependencies

2) Right mouse click on project Maven -> Enable Maven Dependencies

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文