在打包战争之前在Maven构建阶段运行一个Ant任务? [英] Run an ant task in maven build phase before war is packaged?

查看:104
本文介绍了在打包战争之前在Maven构建阶段运行一个Ant任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在部署Web应用程序时,我需要更新UI资源中的一些变量,解压缩一些资产并合并一些文件,目前这是通过ant任务实现的.我正在尝试使用以下方法在Maven构建过程中运行此任务...

When deploying a webapp I need to update some variables in UI resources, unzip some assets and concat some files, currently this is achieved via an ant task. I'm trying to run this task in the maven build process using something like this...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>prepare-package</phase>
            <inherited>false</inherited>
            <configuration>
                <target>
                    <property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
                    <ant antfile="build.xml" target="static-assets" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

以上操作失败,因为尚未将文件复制到目标目录.如果我将阶段设置为打包",则ant任务运行良好,并且所有文件都已创建/修改,但这无济于事,因为在运行ant目标之前已经建立了.war.

The above fails because the files have not yet been copied into target directory. If I set the phase to "package" the ant task runs fine and all the files are created/amended, but it's no help as the .war has already been built before the ant target is run.

基本上,我需要在prepare-package阶段结束时运行我的ant目标.

Basically, I need to run my ant target near the end of the prepare-package phase.

看过生命周期参考我不能锻炼如何将更精细的目标暴露给antrun插件.

Having looked though the Lifecycle Reference I can't workout how to expose the more granular Goals to the antrun plugin.

有什么想法吗?

推荐答案

由于我的评论没有得到任何答案,我想您想继续使用maven-antrun-plugin.

Since I did not get any answer on my comment I guess that you want to stay using maven-antrun-plugin.

根据我所学到的经验,如果两个插件要在同一阶段执行,那么它们将按照在pom.xml中声明的顺序执行.

From what I've learned and experienced, if two plugins are to be executed on the same phase, then they will be executed in the order they are declared in pom.xml.

为此,您必须在maven-antrun-plugin之后的<plugins/>列表中添加maven-war-plugin.

For this to work you will have to add the maven-war-plugin in the <plugins/> list after the maven-antrun-plugin.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>package</phase>
            <inherited>false</inherited>
            <configuration>
                <target>
                    <property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
                    <ant antfile="build.xml" target="static-assets" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <!-- First step is to disable the default-war build step. -->
            <id>default-war</id>
            <phase>none</phase>
        </execution>
        <execution>
            <!-- Second step is to create an exploded war. Done in prepare-package -->
            <id>war-exploded</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>exploded</goal>
            </goals>
        </execution>
        <execution>
            <!-- Last step is to make sure that the war is built in the package phase -->
            <id>custom-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
        </execution>
    </executions>
</plugin>


添加了更多的执行力,以便首先禁用default-war,然后展开战争,最后将战争打包.


Added some more executions so that the default-war is first disabled, then the war is exploded and lastly the war is packaged.

这篇关于在打包战争之前在Maven构建阶段运行一个Ant任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆