问题描述

在这里插入图片描述

问题分析

 	<resource>
        <directory>${project.basedir}/src/main/resources</directory>
        <filtering>true</filtering>
    </resource>

Maven 会过滤字体文件并破坏它们。

解决方案

方法一

	<build>
        <resources>
            <resource>
                <directory>${project.basedir}/build/</directory>
                <excludes>
                    <exclude>**/*.woff</exclude>
                    <exclude>**/*.woff2</exclude>
                    <exclude>**/*.ttf</exclude>
                </excludes>
                <filtering>true</filtering>
                <targetPath>META-INF/resources/</targetPath>
            </resource>
            <resource>
                <directory>${project.basedir}/build/</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*.woff</include>
                    <include>**/*.woff2</include>
                    <include>**/*.ttf</include>
                </includes>
                <targetPath>META-INF/resources/</targetPath>
            </resource>
        </resources>
    </build>

方法二

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <webappDirectory>target/${warExplodedDirectory}</webappDirectory>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/webapp</directory>
                            <excludes>
                                <exclude>**/*.woff</exclude>
                                <exclude>**/*.woff2</exclude>
                                <exclude>**/*.ttf</exclude>
                            </excludes>
                            <filtering>true</filtering>
                            <targetPath>/</targetPath>
                        </resource>
                        <resource>
                            <directory>${basedir}/src/main/webapp</directory>
                            <filtering>false</filtering>
                            <includes>
                                <include>**/*.woff</include>
                                <include>**/*.woff2</include>
                                <include>**/*.ttf</include>
                            </includes>
                            <targetPath>/</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

方法三

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-resources-plugin</artifactId>
     <configuration>
          <nonFilteredFileExtensions>
               <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
               <nonFilteredFileExtension>woff</nonFilteredFileExtension>
               <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
     </configuration>
</plugin>

参考文章

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐