我能';使用tomcat时不能加载字体

我能';使用tomcat时不能加载字体,tomcat,fonts,font-awesome,Tomcat,Fonts,Font Awesome,在使用tomcat加载字体时,我遇到了这样的错误: 1未能解码下载的字体: 1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT 1未能解码下载的字体: 1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT 1未能解码下载的字体: 1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT 1未能解码下载的字体: 1 OTS分析错误:WOFF头中的文件大小不正确 1未能解码下载的字体: 1 OTS分析错误:WOFF头中的文件大小不正确 无法加载资源:net::ERR\u被\u客

在使用tomcat加载字体时,我遇到了这样的错误:

1未能解码下载的字体:

1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT

1未能解码下载的字体:

1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT

1未能解码下载的字体:

1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT

1未能解码下载的字体:

1 OTS分析错误:WOFF头中的文件大小不正确

1未能解码下载的字体:

1 OTS分析错误:WOFF头中的文件大小不正确

无法加载资源:net::ERR\u被\u客户端阻止\u

1未能解码下载的字体:

1 OTS解析错误:FFTM:未对齐的表

1未能解码下载的字体:

1 OTS分析错误:WOFF头中的文件大小不正确

1未能解码下载的字体:

1 OTS分析错误:GDEF:未对齐的表

1未能解码下载的字体:

1 OTS分析错误:表目录的entrySelector不正确

1未能解码下载的字体:

1 OTS分析错误:无法将WOFF 2.0字体转换为SFNT

1未能解码下载的字体:

1 OTS分析错误:WOFF头中的文件大小不正确

1未能解码下载的字体:

1 OTS分析错误:FFTM:表偏移量无效


从spring boot启动时,我没有这个错误。文件夹中有正确的文件。和应加载的字体未正确显示。我可以修复什么使其工作?

如果您使用maven resources插件以选项
true
复制webapp静态资源(包括字体),则可能是资源损坏的原因

在这种情况下,您可以将筛选设置为false(示例):



另一种选择是将资源排除在筛选之外(请参见下面的@eppsilon注释)。

@Mikhail的解决方案对我来说很有效,但我希望继续启用筛选。我通过在
maven resources plugin
部分中添加此XML,从筛选中排除了字体文件:

<nonFilteredFileExtensions>
  <nonFilteredFileExtension>eot</nonFilteredFileExtension>
  <nonFilteredFileExtension>svg</nonFilteredFileExtension>
  <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
  <nonFilteredFileExtension>woff</nonFilteredFileExtension>
  <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
</nonFilteredFileExtensions>

eot
svg
ttf
沃夫
沃夫2

@Mikhail的解决方案对我也很有效。但我已经使用“maven war插件”捆绑了我的发行版。过滤导致字体文件损坏。下面是我的pom文件各自的代码

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <warName>storefront-${version}</warName>
                <warSourceExcludes>portal/**</warSourceExcludes>
                <nonFilteredFileExtensions>
                    <!-- default value contains jpg,jpeg,gif,bmp,png -->
                    <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/portal/dist</directory>
                        <!-- override the destination directory for this resource -->
                        <targetPath />
                        <!-- enable filtering -->
                        <filtering>true</filtering>
                    </resource>
                    <resource>
                        <directory>src/main/webapp/portal/src/assets</directory>
                        <!-- override the destination directory for this resource -->
                        <targetPath>assets</targetPath>
                        <!-- enable filtering -->
                        <filtering>true</filtering>
                    </resource>
                </webResources>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

org.apache.maven.plugins
maven战争插件
3.2.0
店面-${version}
入口/**
eot
svg
ttf
沃夫
沃夫2
src/main/webapp/portal/dist
真的
src/main/webapp/portal/src/assets
资产
真的
假的
正确的链接是:,似乎maven war插件在内部调用maven resources插件,因此也可能是损坏的根源。
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <warName>storefront-${version}</warName>
                <warSourceExcludes>portal/**</warSourceExcludes>
                <nonFilteredFileExtensions>
                    <!-- default value contains jpg,jpeg,gif,bmp,png -->
                    <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/portal/dist</directory>
                        <!-- override the destination directory for this resource -->
                        <targetPath />
                        <!-- enable filtering -->
                        <filtering>true</filtering>
                    </resource>
                    <resource>
                        <directory>src/main/webapp/portal/src/assets</directory>
                        <!-- override the destination directory for this resource -->
                        <targetPath>assets</targetPath>
                        <!-- enable filtering -->
                        <filtering>true</filtering>
                    </resource>
                </webResources>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>