Java 未将 Maven 依赖项添加到 WEB-INF/lib

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

Maven dependencies not being added to WEB-INF/lib

javaeclipsespringmaventomcat

提问by Myna

Fairly new to Spring, Maven, Tomcat and all, I am trying to set up a Spring Web Project in Eclipse, using Maven then deploy the project to Tomcat.

对 Spring、Maven、Tomcat 以及所有内容相当陌生,我试图在 Eclipse 中设置一个 Spring Web 项目,使用 Maven 然后将项目部署到 Tomcat。

I am following this tutorial, suggested by a SOF member : http://www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html

我正在遵循 SOF 成员建议的本教程:http: //www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html

I am having troubles to have Maven add the dependencies specified in pom.xml, to Tomcat's WEB-INF/lib. I have scrupulously followed the steps, but in the part "Run Spring Maven project in eclipse", I do not get the same deployment assembly screenshot. This is what I get :

我在让 Maven 将 , 中指定的依赖项添加pom.xml到 Tomcat 的WEB-INF/lib. 我已经严格按照步骤操作,但是在“在 Eclipse 中运行 Spring Maven 项目”部分中,我没有得到相同的部署程序集屏幕截图。这就是我得到的:

Web deployment assembly in Eclipse, after running <code>mvn eclipse:eclipse -Dwtpversion=2.0</code>

运行 <code>mvn eclipse:eclipse -Dwtpversion=2.0</code>后,Eclipse 中的 Web 部署程序集

I checked in Eclipse that WTP is here, and it is (Help -> Install new Software -> Link "what is installed?") However the version I see for m2e-wtp is 1.0.**. SO I tried to run the mvn eclipse:eclipse -Dwtpversion=1.0command (using version 1.0 instead of 2.0) but still the same problem...

我在 Eclipse 中检查了 WTP 在这里,它是(帮助 -> 安装新软件 -> 链接“安装了什么?”)但是我看到的 m2e-wtp 版本是 1.0.**。所以我尝试运行mvn eclipse:eclipse -Dwtpversion=1.0命令(使用 1.0 版而不是 2.0 版)但仍然是同样的问题......

Anybody has had the same problem ? I have seen similar questions, tried what was suggested but nothing worked for me unfortunately. For example I went in Web Deployment Assembly and clicked Add-> Java Build Path Entriesbut I don't see a Maven Dependenciescheckbox : what I see is a list of entries of the form M2_REPO/.../...

有人遇到过同样的问题吗?我见过类似的问题,尝试了建议的方法,但不幸的是没有任何效果。例如,我进入 Web 部署程序集并单击Add->Java Build Path Entries但我没有看到Maven Dependencies复选框:我看到的是表单条目列表M2_REPO/.../...

Happy Holidays everyone, and thanks in advance for any help on this Myna

祝大家节日快乐,并提前感谢您对此八哥的任何帮助

回答by Eugen

Looks like your "Deployment Assembly" is missing the Maven Dependenciesbeing added to the packaging structure of your project. The way this should look is:

看起来您的“部署程序集”缺少添加到项目打包结构中的Maven 依赖项。这应该看起来是:

enter image description here

在此处输入图片说明

The way to add that in is:
- click on Add
- select Java Build Path Entries
- select Maven Dependencies
- Finish

添加的方法是:
- 点击Add
- 选择Java Build Path Entries
- 选择Maven Dependencies
-Finish

That should add your Maven Dependencies into WEB-INF/lib. In case your project structure is not standard, you can also edit that path by double-clicking inside your Deploy Pathcolumn - in this case, on WEB-INF/lib.

这应该将您的 Maven 依赖项添加到WEB-INF/lib. 如果您的项目结构不标准,您还可以通过在Deploy Path列内双击来编辑该路径- 在这种情况下,在WEB-INF/lib.

Hope that helps.

希望有帮助。

回答by Lucky

It looks like you don't have Maven installed in your eclipse version you use. However you can install Maven Integration for Eclipsefrom the Eclipse Market place. Just Go to Help => Eclipse MarketPlace and Type Maven Integration and install the Maven Integration for eclipse.

看起来您没有在您使用的 eclipse 版本中安装 Maven。但是,您可以Maven Integration for Eclipse从 Eclipse Marketplace 安装。只需转到 Help => Eclipse MarketPlace 并键入 Maven Integration 并为 Eclipse 安装 Maven Integration。

Once you are done eclipse will restart and you will be able to see your jars in the Dependency management as Maven Dependencies.

完成后,eclipse 将重新启动,您将能够在依赖项管理中看到您的 jars 作为 Maven 依赖项。

Visit this url for more info Hope this helps. m2eclipse

访问此网址了解更多信息希望这会有所帮助。 日食

回答by Cary

Open your project folder and find the .classpath file,edit it and add follow code

打开你的项目文件夹并找到 .classpath 文件,编辑它并添加以下代码

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

回答by Alex Mi

I have just had the same problem after improting a new maven web project in my newly created workspace. I checked everything mentioned above: by @Eugen, @lucky, @Cary - all of this was already presented in my project.

在我新创建的工作区中导入一个新的 maven web 项目后,我刚刚遇到了同样的问题。我检查了上面提到的所有内容:@Eugen、@lucky、@Cary - 所有这些都已在我的项目中呈现。

I solved my problem by right-clikcing on my it and selecting Maven-->Update Project

我通过右键单击它并选择 Maven-->Update Project 解决了我的问题