java Eclipse + tomcat - 部署时 ClassNotFound 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12712224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:56:11  来源:igfitidea点击:

Eclipse + tomcat - ClassNotFound exception on deploy

javatomcattomcat7

提问by Ido Barash

I am facing a weird problem with eclipse.

我正面临着一个奇怪的日食问题。

I have a multi-module maven project with CXF, hibernate and spring. If I take the war produced after maven package, and deploy it manually on tomcat 7 - everything works fine. But if I am trying to work with eclipse (Servers -> tomcat) I get the following error:

我有一个带有 CXF、hibernate 和 spring 的多模块 maven 项目。如果我使用 maven 包之后产生的War,并在 tomcat 7 上手动部署它 - 一切正常。但是,如果我尝试使用 Eclipse(服务器 -> tomcat),则会出现以下错误:

    SEVERE: Exception starting filter datasourceFilter
java.lang.ClassNotFoundException: com.X.X.X.X.filter.DataSourceFilter
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

It is worth mentioning that the tomcat which I am trying to integrate with eclipse is the same stand alone tomcat, I deployed the war on manualy. I use eclipse Juno.. if it matters..

值得一提的是,我尝试与eclipse集成的tomcat是同一个独立的tomcat,我手动部署了war。我使用 eclipse Juno .. 如果重要的话..

on my web.xml:

在我的 web.xml 上:

<filter>
        <filter-name>datasourceFilter</filter-name>
        <filter-class>com.X.X.X.X.filter.DataSourceFilter</filter-class>
    </filter>
        <filter-mapping>
        <filter-name>datasourceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Can anyone help me?

谁能帮我?

Idob

伊多布

回答by betomontejo

If you have installed both the Maven Eclipse Pluginand the Maven WTP Pluginthis is automatic. If you don't have these installed, go ahead and install them and then once Eclipse restarts right-click on the project and do a Maven > Update project.... This will internally change the project configuration so the Maven dependencies are copied to the /WEB-INF/libfolder on your deployment target.

如果您已经安装了Maven Eclipse 插件Maven WTP 插件,这是自动的。如果您没有安装这些,请继续安装它们,然后在 Eclipse 重新启动后右键单击该项目并执行Maven > Update project...。这将在内部更改项目配置,以便将 Maven 依赖项复制到/WEB-INF/lib部署目标上的文件夹。

If you don't want to use any of these plug-ins, then you have to go to the Project properties > Deployment Assemblyconfiguration and add your dependencies manually, but again, this is done automatically by these plug-ins.

如果您不想使用这些插件中的任何一个,则必须转到“项目属性”>“部署程序集”配置并手动添加您的依赖项,但同样,这是由这些插件自动完成的。