我需要wro4j配置方面的帮助,才能使用来自webjars的font-awesome。我有下一个配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="http://www.isdc.ro/wro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isdc.ro/wro wro.xsd">
<group name="angular-bootstrap">
<!-- <css>classpath:META-INF/resources/webjars/bootstrap/3.3.4/less/bootstrap.less</css> -->
<!-- <css>classpath:META-INF/resources/webjars/bootstrap/3.3.4/less/theme.less</css> -->
<!-- <css>classpath:META-INF/resources/webjars/font-awesome/4.4.0/less/font-awesome.less</css> -->
<!-- <css>classpath:META-INF/resources/webjars/flag-icon-css/0.7.1/less/flag-icon.less</css> -->
<css>classpath:META-INF/resources/webjars/bootstrap/3.3.4/css/bootstrap.min.css</css>
<css>classpath:META-INF/resources/webjars/bootstrap/3.3.4/css/bootstrap-theme.min.css</css>
<css>classpath:META-INF/resources/webjars/font-awesome/4.4.0/css/font-awesome.min.css</css>
<css>classpath:META-INF/resources/webjars/flag-icon-css/0.7.1/css/flag-icon.min.css</css>
<css>file:${project.basedir}/src/main/wro/main.less</css>
<js>webjar:jquery/2.1.1/jquery.min.js</js>
<js>webjar:angularjs/1.4.4/angular.min.js</js>
<js>webjar:angularjs/1.4.4/angular-route.min.js</js>
<js>webjar:angularjs/1.4.4/angular-cookies.min.js</js>
<js>webjar:angularjs/1.4.4/angular-animate.min.js</js>
<js>webjar:angular-resource/1.4.5/angular-resource.min.js</js>
<js>webjar:angular-translate/2.7.2/angular-translate.min.js</js>
<!-- <js>webjar:angular-translate-loader-static-files/2.6.1-1/angular-translate-loader-static-files.min.js</js> -->
<js>webjar:bootstrap/3.3.4/js/bootstrap.min.js</js>
</group>
</groups>
但是,当加载html页面时,字体字符不会出现。控制台不显示任何错误消息。
这是我对wro4j的Maven配置:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<cssDestinationFolder>${project.build.directory}/generated-resources/static/css</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/generated-resources/static/js</jsDestinationFolder>
<wroFile>${project.build.directory}/wro/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/wro/wro.properties</extraConfigFile>
<contextFolder>${basedir}/src/main/wro</contextFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angularjs</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>flag-icon-css</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>angular-resource</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angular-translate</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angular-translate-loader-static-files</artifactId>
<version>2.6.1-1</version>
</dependency>
</dependencies>
</plugin>
和我的配置属性文件:
#List of preProcessors
preProcessors=cssUrlRewriting,cssImport,lessCssImport
#List of postProcessors
postProcessors=less4j,jsMin,cssMin
最佳答案
也许对您来说太晚了,但是我遇到了同样的问题,并使用maven插件解决了。
问题是wro4j插件不关心webjars依赖项中的任何字体文件,因此最终字体不可用。
第一个插件:将webjars解压缩为${project.build.directory}/unpacked
,将其在artifactItems
节点下列出,并包含目录“fonts”(**/fonts/**/*
)中的所有文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-fonts</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.2.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
<artifactItem>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.5.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<includes>**/fonts/**/*</includes>
<outputDirectory>${project.build.directory}/unpacked</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
第二个插件:将字体文件复制到生成资源的“默认”目录中
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-fonts</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-resources/static/fonts</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/unpacked/META-INF/resources/webjars/bootstrap/3.2.0/fonts</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>${project.build.directory}/unpacked/META-INF/resources/webjars/font-awesome/4.5.0/fonts</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
就我而言,我需要引导字体文件和超棒的字体文件,以便解压缩并复制两个Webjar,但是您可以针对一个或多个Webjar进行配置调整。
我必须说我既不是新手也不是Maven的专家,所以我的答案可以得到改善。
希望这会帮助到别人。 ;)
稻草
关于java - Wro4j,Webjar和Font-awesome,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32913927/