使用tomcat时加载字体时出现此类错误:
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-bold-webfont.woff2
1 OTS解析错误:无法将WOFF 2.0字体转换为SFNT
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-regular-webfont.woff2
1 OTS解析错误:无法将WOFF 2.0字体转换为SFNT
1无法解码下载的字体:https://my-address.com/css/fonts/fontawesome-webfont.woff2?v=4.3.0
1 OTS解析错误:无法将WOFF 2.0字体转换为SFNT
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-regular-webfont.woff
1 OTS解析错误:WOFF标题中的文件大小不正确
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-bold-webfont.woff
1 OTS解析错误:WOFF标题中的文件大小不正确
https://fake.com/无法加载资源:net :: ERR_BLOCKED_BY_CLIENT
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-regular-webfont.ttf
1 OTS解析错误:FFTM:未对齐表
1无法解码下载的字体:https://my-address.com/css/fonts/fontawesome-webfont.woff?v=4.3.0
1 OTS解析错误:WOFF标题中的文件大小不正确
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-bold-webfont.ttf
1 OTS解析错误:GDEF:未对齐的表
1无法解码下载的字体:https://my-address.com/css/fonts/fontawesome-webfont.ttf?v=4.3.0
1 OTS解析错误:表目录
的entrySelector不正确1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-light_0-webfont.woff2
1 OTS解析错误:无法将WOFF 2.0字体转换为SFNT
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-light_0-webfont.woff
1 OTS解析错误:WOFF标题中的文件大小不正确
1无法解码下载的字体:https://my-address.com/css/fonts/robotocondensed-light_0-webfont.ttf
1 OTS解析错误:FFTM:无效表偏移
从spring-boot开始时我没有这个错误。正确的文件位于https://my-address.com/css/fonts/文件夹中。并且应该加载的字体无法正确显示。我可以修理什么才能使它有效?
答案 0 :(得分:9)
如果您使用maven-resources-plugin复制带有选项<filtering>true</filtering>
的webapp静态资源(包括字体),那么它可能是资源损坏的原因。
在这种情况下,您可以将过滤设置为false(示例):
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-frontend-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/build</directory>
<filtering>false</filtering> <!-- SET TO FALSE TO PREVENT RESOURCES CORRUPTION -->
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
More about maven resource filtering
另一种方法是从过滤中排除资源(请参阅下面的@eppsilon评论)。
答案 1 :(得分:1)
@Mikhail的解决方案对我有用,但我想继续过滤。我通过在<configuration>
的{{1}}部分添加此XML来排除过滤字体文件:
maven-resources-plugin
答案 2 :(得分:1)
@ Mikhail的解决方案也适用于我。但我使用'maven-war-plugin'来捆绑我的发行版。过滤导致字体文件损坏。以下是我的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>