简体   繁体   English

为什么在Eclipse中构建Maven项目后,“WEB-INF / lib”文件夹显示为空?

[英]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 packagemvn (甚至是: 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.

相关问题 Maven不会在WEB-INF / lib文件夹中复制spring jars - Maven does not copy spring jars in WEB-INF/lib folder 我的Maven项目没有将依赖项导入WEB-INF / lib文件夹 - My maven project does not import dependencies to WEB-INF/lib folder 为什么Tomcat库文件夹WEB-INF / lib是空的? - Why Tomcat library folder WEB-INF/lib is empty? 为什么M2e插件在Maven jar项目的目标文件夹中构建为WEB-INF / classs? - Why does the m2e plugin build to a WEB-INF/classes in the target folder for a maven jar project? 在 Maven 项目 POM 中输入<systempath>标签未包含在生成的战争文件 WEB-INF\lib 文件夹中</systempath> - Enteries in Maven Project POM with <systemPath> tag does not get included in the generated war file WEB-INF\lib folder Eclipse Java Web项目手册在WEB-INF中设置lib文件夹 - Eclipse java web project manual set lib folder in WEB-INF Maven,GWT,Google Eclipse插件,在依赖项项目处于战争状态时无法将jar复制到WEB-INF / lib - Maven, GWT, Google Eclipse plugin, can not copy jar to WEB-INF/lib when dependency project is war Maven2 IDEA项目,如何手动添加到web-inf/lib文件夹? - Maven2 IDEA project, how to manually add to web-inf/lib folder? Maven依赖项不会复制到eclipse中的WEB-INF / lib - Maven dependencies are not copied to WEB-INF/lib in eclipse Maven构建损坏/ WEB-INF / lib文件夹中的jar文件 - Maven build corrupting jar files in /WEB-INF/lib folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM