Tomcat – I can’t load fonts while using tomcat

font-awesomefontstomcat

I have such errors while loading fonts when using tomcat:

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-bold-webfont.woff2

1 OTS parsing error: Failed to convert WOFF 2.0 font to SFNT

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-regular-webfont.woff2

1 OTS parsing error: Failed to convert WOFF 2.0 font to SFNT

1 Failed to decode downloaded font: https://my-address.com/css/fonts/fontawesome-webfont.woff2?v=4.3.0

1 OTS parsing error: Failed to convert WOFF 2.0 font to SFNT

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-regular-webfont.woff

1 OTS parsing error: incorrect file size in WOFF header

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-bold-webfont.woff

1 OTS parsing error: incorrect file size in WOFF header

https://fake.com/ Failed to load resource: net::ERR_BLOCKED_BY_CLIENT

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-regular-webfont.ttf

1 OTS parsing error: FFTM: misaligned table

1 Failed to decode downloaded font: https://my-address.com/css/fonts/fontawesome-webfont.woff?v=4.3.0

1 OTS parsing error: incorrect file size in WOFF header

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-bold-webfont.ttf

1 OTS parsing error: GDEF: misaligned table

1 Failed to decode downloaded font: https://my-address.com/css/fonts/fontawesome-webfont.ttf?v=4.3.0

1 OTS parsing error: incorrect entrySelector for table directory

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-light_0-webfont.woff2

1 OTS parsing error: Failed to convert WOFF 2.0 font to SFNT

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-light_0-webfont.woff

1 OTS parsing error: incorrect file size in WOFF header

1 Failed to decode downloaded font: https://my-address.com/css/fonts/robotocondensed-light_0-webfont.ttf

1 OTS parsing error: FFTM: invalid table offset

I don't have this errors when starting from spring-boot. Proper files are in https://my-address.com/css/fonts/ folder. And fonts that should be loaded, aren't displayed correctly. What could I repair to make it works?

Best Answer

If you use maven-resources-plugin to copy webapp static resources (including fonts) with option <filtering>true</filtering> then it could be the reason for corruption of resources.

In such case you can set filtering to false (example):

<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

Another alternative is to exclude resources from filtering (see @eppsilon comment below).

Related Topic