java - Maven WAR 插件 - 更改前端资源位置

标签 java maven war maven-plugin maven-war-plugin

缩小后,我的 webapp 内容如下:

WEB-INF
assets
favicon
i18n
scripts
dist
index.html
//other things

dist里面我有压缩的样式、脚本等...但是Maven WAR插件将所有内容复制到WAR,这导致WAR包含未压缩的源代码。我尝试更改 webResources 的目录:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven-war-plugin.version}</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
         packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
         <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp/dist</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

但是什么都没有改变。谁能帮我这个?预先感谢您的每一个回答。

最佳答案

packagingExcludes 接受不包含的资源的逗号分隔列表。将您想要排除的所有目录添加到其中,例如

<packagingExcludes>
    WEB-INF/lib/tomcat-*.jar,
    scripts
</packagingExcludes>

您还需要确保资源不包含在 Maven 资源插件中。

我建议将所有不希望出现在 war 文件中的文件移出目录,而不是手动处理所有排除项,maven 默认情况下希望包含资源。您可以将它们移至例如src/main/uncompressedResources.这样它们仍然会在项目中,但 Maven 默认情况下不会包含它们。

关于java - Maven WAR 插件 - 更改前端资源位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39556086/

相关文章:

Java - 用鼠标滚轮滚动和缩放?

Java 程序在为 k-gram 索引语料库时突然变慢

java - 为什么 Maven 不下载 jar 文件但可以下载插件?

java - 执行 war 时加载主类失败

maven - 如何用maven替换web.xml中的contex-param值?

java - @Size 注释来验证字段

java - 有没有某种方法可以在浏览器中或嵌入在java应用程序中的浏览器中启用跨站点javascript

java - mvn执行:java fails with FileNotFoundException

java - Maven com.google 无法解析输入

java - 如何使用maven将可执行文件放入war文件