Wro4j, webjars and font-awesome



我需要wro4j配置的帮助,从webjar使用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插件不关心任何字体文件在webjar的依赖关系,所以字体是不可用的。

第一个插件:将webjar解压到${project.build.directory}/unpacked, artifactItems节点下列出的webjar包括目录"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>

第二个插件:复制字体文件到generate -resources "default"目录

        <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>

在我的情况下,我需要bootstrap字体文件和font-awesome字体文件,所以我解包并复制这两个webjar,但是你可以为一个或两个以上的webjar调整配置。

我必须说,我不是maven的新手,也不是专家,所以我的答案可以改进。

希望这将帮助某人。;)

稻草

同样,在最新版本中检查这个,作为一个提示,检查文件夹/target中打包的jar文件中的优步jar:

webjar -locator library:

。pom依赖性:

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>font-awesome</artifactId>
        <version>5.2.0</version>
    </dependency>
...
<link rel="stylesheet"
th:href="@{/webjars/font-awesome/5.2.0/css/fontawesome.min.css}">

或者使用webjar -locator:

。pom依赖性:

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator</artifactId>
        <version>0.36</version>
    </dependency>
...
   <link rel="stylesheet"
th:href="@{/webjars/font-awesome/css/fontawesome.min.css}">

您正在使用wro4j maven插件。在应用处理器时,它引用具有以下url形式的类路径资源:

classpath:META-INF/resources/webjars/flag-icon-css/0.7.1/css/flag-icon.min.css, imageUrl ../flags/1x1/yt.svg

这类url是无效的,因为它们试图访问非公共的类路径资源。最简单的解决方法是使用运行时解决方案(使用WroFilter),它会处理类路径资源。另一种方法可能是混合解决方案,其中maven插件用于生成包,而servlet(类似于WroFilter所做的)负责提供类路径资源。您可能会发现webjar -servlet项目对此很有用。

我将尝试创建一个示例项目,该项目适用于运行时和构建时解决方案,该解决方案与您的设置类似,并将在评论中让您知道何时可用

相关内容

  • 没有找到相关文章

最新更新