SSM项目启动tomcat抛出ClassNotFoundException

来源:互联网 发布:淘宝客怎么加群 编辑:程序博客网 时间:2024/05/01 23:34

项目采用ssm框架,我为了让项目的jar包可以让其他project也可以使用,将项目需要的jar包放进一个Faceted Project中,这是模仿之前实习公司的作法,然后配置web.xml、applicationContext.xml等,各项完事,在BuildPath正常,但是在启动tomcat时反复提示

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

我就很纳闷,然后突然想起来之前遇到类似的问题,是通过修改项目的.classpath文件解决,我于是打开了该文件,果然看到原本正确的设置是这样:

......    <classpathentry kind="lib" path="/Lib/castor-1.0.1-xml.jar">        <attributes>            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>        </attributes>    </classpathentry>    <classpathentry kind="lib" path="/Lib/commons-beanutils.jar">        <attributes>            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>        </attributes>    </classpathentry>    <classpathentry kind="lib" path="/Lib/commons-collections-3.2.1.jar">        <attributes>            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>        </attributes>    </classpathentry>    <classpathentry kind="lib" path="/Lib/commons-dbcp-1.4.jar">        <attributes>            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>        </attributes>    </classpathentry>    <classpathentry kind="lib" path="/Lib/commons-digester.jar">......

但我的是这样的

......        <attributes>            <attribute name="owner.project.facets" value="java"/>        </attributes>    </classpathentry>    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">        <attributes>            <attribute name="owner.project.facets" value="jst.web"/>        </attributes>    </classpathentry>    <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>    <classpathentry kind="lib" path="/Lib/antlr-2.7.6.jar"/>    <classpathentry kind="lib" path="/Lib/aopalliance-1.0.jar"/>    <classpathentry kind="lib" path="/Lib/cglib-2.2.jar"/>    <classpathentry kind="lib" path="/Lib/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar"/>    <classpathentry kind="lib" path="/Lib/commons-collections-3.1.jar"/>    <classpathentry kind="lib" path="/Lib/commons-fileupload-1.2.1.jar"/>    <classpathentry kind="lib" path="/Lib/commons-io-1.3.2.jar"/>    <classpathentry kind="lib" path="/Lib/commons-lang.jar"/>    <classpathentry kind="lib" path="/Lib/commons-logging-1.1.1.jar"/>    <classpathentry kind="lib" path="/Lib/dom4j-1.6.1.jar"/>......

也就是如果通过引用外部项目的jar包后需要.classpath文件中设置依赖路径,否则myeclipse就找到这些jar包,就会报出那个错误。

于是将文件中的
/>
替换为
><attributes><attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/></attributes></classpathentry>
问题解决。

这个问题充分说明,每个人问题都不一定是一样的,遇到问题还是需要自己找到问题的根源去解决。只在网上搜是治标不治本的。

0 0
原创粉丝点击