Eclipse 未正确部署我的 Web 应用程序

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

Eclipse not deploying my web app properly

eclipsespringmavenspring-mvc

提问by Gabriel Sanmartin

I am trying to create a base Spring project with Maven on Eclipse Kepler (with m2eclipse installed). No errors are reported by Eclipse but when I hit Run on Server (or run Maven Install) only the original files from META-INF and WEB-INF files are deployed. This does not include my dispatcher-servlet.xml config file thus causing a FileNotFoundException:

我正在尝试在 Eclipse Kepler(安装了 m2eclipse)上使用 Maven 创建一个基本的 Spring 项目。Eclipse 没有报告错误,但是当我点击在服务器上运行(或运行 Maven 安装)时,只部署了 META-INF 和 WEB-INF 文件中的原始文件。这不包括我的 dispatcher-servlet.xml 配置文件,从而导致FileNotFoundException

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]

How can I fix this?

我怎样才能解决这个问题?

This is my web.xml:

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/dispatcher-servlet.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

And this is a screencap of my project's folder:

这是我的项目文件夹的屏幕截图:

enter image description here

在此处输入图片说明

As you can see only selected files are shown in Deployed resources.

如您所见,已部署的资源中仅显示选定的文件。

回答by Suryaprakash Pisay

Since it is a maven project .

既然是maven项目。

you might have converted maven project to dynamic web project I guess.

我猜您可能已经将 Maven 项目转换为动态 Web 项目。

Follow the steps

按照步骤

  1. Go to project properties (right click at last click peoperties)

  2. click/select Deployment assembly at the left side

  3. the root(/) deploy path may be pointing to src/main/webapp , select this and click remove button

  4. click on add button , select a directive type folder, select your WebContent folder

  1. 转到项目属性(最后单击鼠标右键单击peoperties)

  2. 单击/选择左侧的部署程序集

  3. root(/) 部署路径可能指向 src/main/webapp ,选择它并单击删除按钮

  4. 单击添加按钮,选择指令类型文件夹,选择您的 WebContent 文件夹

Now try to clean and run your application on server.

现在尝试清理并在服务器上运行您的应用程序。

Solution 2

解决方案2

  1. Actually you need to copy/put all your WebContentfiles and folderto src/main/webapp
  1. 实际上,您需要将所有WebContent文件和文件夹复制/放入src/main/webapp

and restart your server.

并重新启动您的服务器。

Note that the maven dynamic web project it always look in to src/main/webapp by default.

请注意,maven 动态 web 项目默认总是在 src/main/webapp 中查找。

Hope it helps

希望能帮助到你

回答by Rakin Afser

Add <sourceDirectory>src</sourceDirectory>in the <build>block.

添加<sourceDirectory>src</sourceDirectory><build>块中。

Then Run Maven with "clean install" goal.

然后以“全新安装”目标运行 Maven。

And refresh your project.

并刷新您的项目。

Now check your target folder. You should see war file or * extension file. Hope it will solve

现在检查您的目标文件夹。您应该会看到 war 文件或 * 扩展名文件。希望能解决