English 中文(简体)
呼唤在maven- entrun- plutin 中的每个人
原标题:Calling foreach in maven-antrun-plugin

我试图设置修道院 执行LESS CSS 预处理器 在我的网络项目的目录上。 基本流程是 :

  1. Maven calls maven-antrun-plugin.
  2. Ant-contrib <foreach/> loops through a directory and finds all the .less files and calls a target.
  3. The target executes Rhino, which executes LESS which converts the file.

为此,我有以下XML:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <target name="processLessFile">
                            <!-- ... -->
                        </target>
                        <target name="main">
                            <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
                            <property name="css.dir" location="src/main/webapp/css"/>
                            <foreach param="file" target="processLessFile">
                                <fileset dir="${css.dir}">
                                    <filename name="**/*.less" />
                                </fileset>
                            </foreach>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>ant</groupId>
                    <artifactId>ant-contrib</artifactId>
                    <version>1.0b2</version>
                </dependency>
            </dependencies>
        </plugin>

我遇到的问题是“ 主” 目标开始执行, 但是在 中失败 :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project model-web-project: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /Users/.../pom.xml:4: Unexpected element "{http://maven.apache.org/POM/4.0.0}project" {antlib:org.apache.tools.ant}project
[ERROR] around Ant part ...<foreach param="file" target="processLessFile">... @ 6:50 in /Users/.../target/antrun/build-main.xml
[ERROR] -> [Help 1]

Ant 似乎有些东西导致它尝试读取 POM 文件, 可能搜索目标。 我看到两个目标被生成到文件目标/ antrun/ building- main. xml 和目标/ antrun/ building- processLessFile. xml 中, 所以它应该搜索的目录就是这个 。

最佳回答

蚂蚁插件似乎不支持多个目标部分的声明。 您可以检查生成的 ANT 脚本, 查看我在说什么 :

target/antrun/build-main.xml

正在深入挖掘>plug-in documents 的以下文件:“http://maven.pache.org/plugins/maven-antrun-plugin/index.html”

此插件无意提供污染 POM 的手段, 所以它鼓励您将全部 Ant 任务移到 build. xml 文件, 并使用 Ant s 任务从 POM 调用它 。

胡言乱语,但忠告是有道理的。我建议把你的ANT逻辑转换成一个专用文件,引用如下:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                            <ant antfile="${basedir}/src/main/ant/build.xml"/>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
问题回答




相关问题
i want to continously run my java threads

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was ...

Subant targets instead of ant

I m having a problem with subant and have no ideas any more. Can anyone help? Using Ant to replace some strings for other (i.e Productname and Version for "Foo" and "1.2") I used ...

java ant buildfile for project with dependencies

I am new to ant, but am trying to create an ant script that builds my current proeject with another project as a dependency. I have the ant script building my current project, but am unsure how to add ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签