Maven Resources Plugin and Binary Fonts

Copy WAR resources without corrupt binary files

Advertisements

The Maven Resources Plugin copies project resources into the output dir during the creation of the WAR. During this phase the plugin performs the filtering operation, where the variables in the resource files are replaced with the specified values. But this filtering operation does not have to be done for binary files, to prevent these files from being corrupted. For example binary files that can be corrupted by the filtering phase of the Maven Resources Plugin are the fonts.

If there are any corrupted fonts in the deployed WAR, just check with the developer’s tools that each browser provides, if there are any errors in the font decoding phase of the browser itself. For example, as in this case:

fonts_corruptedmessages such as “Failed to decode downloaded font”, or “OTS parsing error: Failed to convert WOFF 2 font to SFNT”, or “incorrect file size in WOFF header”, or “GDEF: invalid table offset” are all signs that binary fonts are corrupt.

To avoid these problems just add the exclusions in the configuration section of the plugin in the pom.xml file. For example:

       
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <configuration>
          <delimiters>
            <delimiter>ยง</delimiter>
          </delimiters>
          <useDefaultDelimiters>false</useDefaultDelimiters>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>ico</nonFilteredFileExtension>
            <nonFilteredFileExtension>jpg</nonFilteredFileExtension>
            <nonFilteredFileExtension>png</nonFilteredFileExtension>
            <nonFilteredFileExtension>eot</nonFilteredFileExtension>
            <nonFilteredFileExtension>svg</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
        </configuration>
      </plugin>

in this case all files with extensions declared in nonFilteredFileExtensions will only be copied to the output dir without being filtered.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s