spring 未在 Eclipse Tomcat 实例上部署 Maven 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12931750/
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-09-08 05:26:28  来源:igfitidea点击:

Maven dependencies not deployed on Eclipse Tomcat instance

eclipsespringtomcatmaven

提问by MaVVamaldo

I'm using Spring Tool Suite 3.1 and I have some issues deploying a web application to tomcat.

我正在使用 Spring Tool Suite 3.1,但在将 Web 应用程序部署到 tomcat 时遇到了一些问题。

When I hit "run on server" and the server starts it throws the famous:

当我点击“在服务器上运行”并且服务器启动时,它会抛出著名的:

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

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

So I check the /wtpwebappsdirectory to find that the project is deployed, but inside the libfolder only a few libraries are present. I completely miss the rationale behind their selection. Of course the libraries related to spring aren't there. Can anyone help?

所以我检查/wtpwebapps目录发现项目已经部署了,但是lib文件夹里面只有几个库。我完全想念他们选择背后的理由。当然,与 spring 相关的库不在那里。任何人都可以帮忙吗?

This is my org.eclipse.wst.common.commonentfile, maybe it can be useful:

这是我的org.eclipse.wst.common.commonent文件,也许有用:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="Checkup">
    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
    <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
    <property name="context-root" value="Checkup"/>
    <property name="java-output-path" value="/Checkup/build/classes"/>
</wb-module>

EDIT:

编辑:

you can see the list of maven plugin embedded with STS installation (no customizations)

您可以看到嵌入 STS 安装的 maven 插件列表(无自定义)

STS maven plugins

STS Maven 插件

回答by NimChimpsky

add maven dependencies to deployment assembly, by right clicking project - navigating to deployment assembly, and then adding the maven dependencies library.

通过右键单击项目 - 导航到部署程序集,然后添加 Maven 依赖项库,将 maven 依赖项添加到部署程序集。

回答by MaVVamaldo

after hours of pain it seems the problem is solved thanks to magics or something. The "mysterious" procedure that fixed the things is the following:

经过数小时的痛苦,似乎问题得到了解决,这要归功于魔法之类的。修复这些东西的“神秘”程序如下:

  1. run your project on tomcat and get the error
  2. clean tomcat rclick ---> clean (not clean working directory) while your project is still on the server
  3. run the server again
  1. 在 tomcat 上运行你的项目并得到错误
  2. 清理 tomcat rclick ---> 清理(不清理工作目录)而您的项目仍在服务器上
  3. 再次运行服务器

the tricky part is cleaning tomcat when the web app is still deployed. I really don't know why it works. If you stop the server, remove the application, clean the server and redeploy the application agian you get the error. I won't dare to understand further, I accept the mystery.

棘手的部分是在仍部署 Web 应用程序时清理 tomcat。我真的不知道它为什么有效。如果您停止服务器,删除应用程序,清理服务器并重新部署应用程序,您会收到错误消息。我不敢再进一步了解,我接受了这个谜。

回答by Jianwu Chen

NimChimpsky's answer is right solution for me. Only it's not very specific. The detailed steps is: right click project -> select "properties" -> search "Deployment Assembly" -> click "Add" button -> add "Maven Dependent"

NimChimpsky 的回答对我来说是正确的解决方案。只是它不是很具体。详细步骤是:右键项目->选择“属性”->搜索“部署程序集”->点击“添加”按钮->添加“Maven依赖”

回答by Deepak Shrivastava

Another way to fix this issue is by using the terminal (Linux or Mac) or the command prompt (Windows). Navigate to the folder of the project and use the following command:

解决此问题的另一种方法是使用终端(Linux 或 Mac)或命令提示符 (Windows)。导航到项目的文件夹并使用以下命令:

mvn eclipse:eclipse -Dwtpversion=2.0

Once the command is successfully executed, a new file called org.eclipse.wst.common.componentwill be created inside the .settingsfolder of the project.

命令成功执行后,将在项目的.settings文件夹中创建一个名为org.eclipse.wst.common.component的新文件。

Start the server and it should pick all the dependent libraries automatically.

启动服务器,它应该自动选择所有依赖库。