I'm working on a java webapp that uses icon fonts for the icons. I know I can create an icon font from individual SVG files using the IcoMoon app, but I don't want to manually have to recreate the font each time an icon needs to be added. So I want to do it automatically, preferably as part of the Maven build. Is there a way to let Maven generate the icon font from the individual SVG files?
Asked
Active
Viewed 950 times
1 Answers
0
I'm not sure there is a maven plugin to perform that specific function.
I'd suggest you use grunt http://gruntjs.com/ which runs on node and the grunt web font plugin https://github.com/sapegin/grunt-webfont
If you created your GruntFile.js
in src/main/resources/grunt
module.exports = function(grunt) {
//Project Configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), //Details about the package were creating
webfont: {
icons: {
src : "icons/svg/*.svg",
dest: '../META-INF/resources/font',
destCss:'../META-INF/resources/css',
options: {
font: 'myfont',
fontFilename: 'MyFont',
types:'eot,woff,ttf,svg',
engine:'node',
stylesheet:'less',
htmlDemo:false
}
}
}
});
grunt.loadNpmTasks('grunt-webfont');
grunt.registerTask('default', ['webfont']);
};
You can then in your pom run
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>Grunt run</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>grunt</executable>
<workingDirectory>${basedir}/src/main/resources/grunt</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
You probably want to exclude src/main/resources/grunt from maven resources and make sure that the icon file doesn't go through maven resource filtering as that tends to break them.

Martin Cassidy
- 686
- 1
- 9
- 28