[英]Why does “WEB-INF/lib” folder appear to be empty after a Maven project is built within Eclipse?
i followed this spring-mvc-tutorial using eclipse, but after i call Maven / Update Projects my WEB-INF/lib directory remains empty. 我使用eclipse跟踪了这个spring-mvc-tutorial ,但是在我调用Maven / Update Projects之后,我的WEB-INF / lib目录仍然是空的。
this is how my project explorer looks: 这就是我的项目浏览器的外观:
i also see no mistake in my Deployment Assembly settings: 我也看到我的部署程序集设置没有错误:
this is the pom.xml file i use: 这是我使用的pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CrunchifySpringMVCTutorial</groupId>
<artifactId>CrunchifySpringMVCTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
i even switched to a new workspace as suggested in this link , but nothing helped 我甚至切换到这个链接建议的新工作区,但没有任何帮助
EDIT: when i start the server i get the error: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 编辑:当我启动服务器时,我收到错误:java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet
Eclipse virtually hides the files from the view that displays the WEB-INF/lib
folder in a Maven-managed Dynamic Web-Project project. Eclipse虚拟地隐藏了在Maven管理的Dynamic Web-Project项目中显示
WEB-INF/lib
文件夹的视图中的文件。 As your first screenshot indicates, the "Maven Dependencies" library entry has been successfully added to your classpath in the background by Eclipse - it contains every dependency referenced in your pom.xml
. 正如您的第一个屏幕截图所示,Eclipse中已成功将“Maven Dependencies”库条目添加到您的类路径中 - 它包含您的
pom.xml
引用的每个依赖项。
The intention behind this behavior for that is/might be: You - as a developer - are not supposed to copy any .jar files manually to WEB-INF/lib
, cause that way you would kind of cheat around the idea behind a (Maven-) managed project. 这种行为背后的意图是/可能是:你 - 作为一个开发人员 - 不应该手动将任何.jar文件复制到
WEB-INF/lib
,因为这样你就会有一种欺骗背后的想法(Maven) - )管理项目。
In a certain way, this makes sense as Maven performs any dependency management for you and thus resolves and "bundles" any third-party (or your own) artifacts. 在某种程度上,这是有意义的,因为Maven为您执行任何依赖管理,从而解析并“捆绑”任何第三方(或您自己的)工件。
If you run a mvn
with the goals clean package
(or even: clean install
) it will produce a .war
file for you in the "target" folder of your project. 如果你运行带有目标
clean package
的mvn
(甚至是: clean install
),它将在你项目的“target”文件夹中为你生成一个.war
文件。 If you extract that .war
file you should find a WEB-INF/lib
folder that contains all dependencies bundled into your deployable artifact. 如果您提取该
.war
文件,您应该找到一个WEB-INF/lib
文件夹,其中包含捆绑到可部署工件中的所有依赖项。
I think it is correct. 我认为这是正确的。
Libraries are copied into target after build, not into project itself. 库在构建后复制到目标中,而不是项目本身。
Also Step 8 in the tutorial you pasted shows the same (empty lib folder) 此外,您粘贴的教程中的步骤8显示相同的(空的lib文件夹)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.