首页 \ 问答 \ Gradle - War任务:如何在.war文件中包含特定路径中的特定文件(Gradle - War task: how include into the .war file a specific file from a specific path)

Gradle - War任务:如何在.war文件中包含特定路径中的特定文件(Gradle - War task: how include into the .war file a specific file from a specific path)

我正在使用多模块项目。

以下是强制性的

apply plugin: 'war'

project(':thymeleaf-02-web') {

    description 'Web (HTML, JS, CSS)'

    dependencies {

        exportedProjects.each{
            if("$it"!=":thymeleaf-02-web")
                compile project("$it")
        }

    }

    webAppDirName = 'src/main/resources'

    war {
        version=''
        baseName = warBaseName
    }

}

带有src/main/resources webAppDirName的值完全是强制性的,它不是我们期待的与WEB-INF位置有关的工作,因为我正在使用Thymeleaf ,否则许多@Test方法会失败,它关于Testing @Controller关于Spring

现在我有必要的情况下,我需要web应用程序的web.xml文件来配置<error-page> 。 它通常位于src/main/webapp/WEB-INF/ location中,但是当我创建.war文件并且它已部署时, web.xml从未考虑过,因此不包括在内。

我曾尝试添加以下内容:

dependencies {

    compile fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')
    runtime fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')


    exportedProjects.each{
        if("$it"!=":thymeleaf-02-web")
            compile project("$it")
    }

}

但没有。 目前,我必须手动web.xml文件复制/粘贴到已部署的 .war文件中。

那么什么是正确的配置?


I am working with a multi module project.

The following is mandatory

apply plugin: 'war'

project(':thymeleaf-02-web') {

    description 'Web (HTML, JS, CSS)'

    dependencies {

        exportedProjects.each{
            if("$it"!=":thymeleaf-02-web")
                compile project("$it")
        }

    }

    webAppDirName = 'src/main/resources'

    war {
        version=''
        baseName = warBaseName
    }

}

The value for webAppDirName with src/main/resources is totally mandatory, it is not the expected working about with the WEB-INF location, because I am working with Thymeleaf, otherwise many @Test methods fail, it about Testing @Controller about Spring.

Now I have the mandatory case that I need for the web app the web.xml file to configure the <error-page>. It is located as usual within the src/main/webapp/WEB-INF/ location, but when I create the .war file and it is deployed the web.xml never was taken in consideration and thus is not included.

I have tried the following addition:

dependencies {

    compile fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')
    runtime fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')


    exportedProjects.each{
        if("$it"!=":thymeleaf-02-web")
            compile project("$it")
    }

}

But nothing. For the moment I must copy/paste manually the web.xml file into the deployed .war file.

Thus what is the correct configuration?


原文:https://stackoverflow.com/questions/50164269
更新时间:2022-02-25 21:02

最满意答案

http://www.facebook.com发送一个301 Moved Permanently响应,重定向到https://www.facebook.com

看起来,重定向导致请求比完全跨域故障更安静地失败。 但是,这两个请求都会失败。

编辑

根据W3C Ajax规范

如果响应的HTTP状态码为301,302,303,307或308 ...

  1. 将请求URL设置为Location标头传送的URL。
  2. 如果源出处和请求URL的来源是相同的,则在观察同源请求事件规则时透明地遵循重定向。
  3. 否则,请遵循跨源请求步骤并终止该算法的步骤。

文本“透明地遵循重定向”意味着Ajax应该将301重定向的目标视为原始目标。 但是,执行重定向时,将根据新的目标原点重新检查同源策略。

目标域也必须与请求脚本具有相同的来源,或者必须使用允许请求源访问的CORS头进行响应。


http://www.facebook.com sends a 301 Moved Permanently response, which redirects to https://www.facebook.com.

It appears that the redirect causes the request to fail more quietly than an outright cross-domain failure. However, both requests do fail.

EDIT

According to the W3C Ajax specification:

If the response has an HTTP status code of 301, 302, 303, 307, or 308 ...

  1. Set the request URL to the URL conveyed by the Location header.
  2. If the source origin and the origin of request URL are same origin transparently follow the redirect while observing the same-origin request event rules.
  3. Otherwise, follow the cross-origin request steps and terminate the steps for this algorithm.

The text "transparently follow the redirect" means that Ajax should treat the target of 301 redirects as the original target. However, when performing a redirect, the same-origin policy is re-checked against the new target origin.

The target domain must also have the same origin as the requesting script, or it must respond with CORS headers that allow access by the requesting origin.

相关问答

更多
  • 是的,人们都是正确的只有在webapps而不是混合phonegap应用程序中需要相同的来源策略。 您需要检查您的域名白名单,只需在res - > xml文件夹中的config.xml中检查它。 为了访问XML Web服务,您需要确保您的SOAP消息正确地形成。 尝试捕捉确切的错误。 Yes, people are correct the Same Origin Policy is needed only in webApps not hybrid phonegap apps. You need to che ...
  • 基本规则 同源策略适用于从页面到与GET调用之外的网页域(包括子域)不同的域的任何HTTP调用。 这意味着如果您向页面添加脚本标记,加载图像或执行使用GET方法的任何类型的HTTP调用 - 那么您没有问题。 另一方面,如果您尝试使用其他方法(如POST,PUT,DELETE等)到另一个域,则浏览器将阻止该调用并抛出错误。 这方面的方法 但是,有几种方法可以解决这个问题。 第一种是使用GET调用,但让另一方将该调用解释为其他内容。 一个很好的例子是一种名为JSONP的技术,我们在这里向页面添加一个脚本标记(这 ...
  • 尝试这个: "C:\Users\Bertho Joris\AppData\Local\Google\Chrome\Application\chrome.exe" --disable-web-security 记下""的位置 Try this: "C:\Users\Bertho Joris\AppData\Local\Google\Chrome\Application\chrome.exe" --disable-web-security Take note of the location of the ""
  • http://www.facebook.com发送一个301 Moved Permanently响应,重定向到https://www.facebook.com 。 看起来,重定向导致请求比完全跨域故障更安静地失败。 但是,这两个请求都会失败。 编辑 根据W3C Ajax规范 : 如果响应的HTTP状态码为301,302,303,307或308 ... 将请求URL设置为Location标头传送的URL。 如果源出处和请求URL的来源是相同的,则在观察同源请求事件规则时透明地遵循重定向。 否则,请遵循跨源请求 ...
  • 在处理这类事情时,人们通常会想到三个起源: 页面(http://example.com/) 脚本(http://example.net/foo.js) 数据(http://example.net/bar.json) 如果使用“相同”来源,在制定时会比较哪些被比较的混淆。 只有页面的来源和数据很重要 。 脚本本身加载的地方是无关紧要的。 在这种情况下: 页面:A 脚本:B(无关紧要) 数据:B 由于页面和数据来自不同的来源,因此您无法从页面中读取数据。 由于您要发出POST请求:通过A代理HTTP请求。(JS ...
  • 机器人伍兹肯定是在正确的轨道上。 在处理本机应用程序时,您在某种意义上是从file://而不是从https://发出请求。 由于您没有通过HTTP协议发出请求,因此不适用相同的规则。 从您的原生移动应用程序发出请求时,您应该向任何域发出请求而不会出现任何问题。 您只需要将域添加到PhoneGap / Cordova中的白名单中,如果您将整个页面替换为webview中的正常内容(通常不会发生)(通常只是从服务器请求数据块,而不是做一个window.location改变)。 Robot Woods is def ...
  • CORS规则或相同的来源政策是否适用于此? 是。 根据同源策略,r.com上的脚本将无法读取它对a.com发出的任何请求的结果。 因此它将无法读取登录标记。 如果您添加CORS支持,那么您可以选择允许r.com访问,在这种情况下,它将能够与您的网站自由交互。 请注意,如果r.com是恶意网站,并且能够让用户输入密码,那么浏览器的相同原始策略实际上不会保护用户。 恶意页面可以将信息发送到他们自己的服务器,通过该用户的凭据可以将任意请求发送到您的站点。 r.com的JS可以访问发送到加载a.com的框架的数据吗 ...
  • IFrame通常免于同一原产地政策。 但是,如果您在致电http://google.com时查看HTTP响应标头,则会看到以下标头: x-frame-options:SAMEORIGIN 这明确告诉您的浏览器它应该阻止页面跨源显示 。 MDN描述了这种特殊行为: 以下是可能嵌入跨源的资源的一些示例: [...] 任何有和