---
title: "maven中pom.xml文件中执行ant命令"
author: "software_developer"
date: "2013-06-28T21:12:08Z"
tags: []
categories: ["编程语言"]
slug: "maven-pom-xml-ant"
draft: false
lastmod: "2013-06-28T21:12:07Z"
id: 1896229
url: "https://software-developer.iteye.com/blog/1896229"
---

**需求：**

      最近在学习阿里巴巴的开源框架Dubbo（分布式服务框架），在做练习例子中将provider（服务提供者）部署到另一台电脑上。实现该provider采用的是Dubbo+Spring+MyBatis实现，该provider无需页面，只需到启动就可以。而Dubbo提供的一个默认启动类(com.alibaba.dubbo.container.Main)，默认会去加载jar包中META-INF/spring/目录下的文件，所以我通过maven打包时就需要将spring配置文件放置到META-INF/spring/目录下。

 

**实现：**

主要实现是在pom.xml文件中添加maven-antrun-plugin插件，然后去执行对应的ant命令。

配置如下：

```

```

```
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>prepare-package</id>
<phase>prepare-package</phase>
<configuration>
<target>
<mkdir dir="${project.build.outputDirectory}/META-INF/spring"/>
<copy file="${project.build.outputDirectory}/applicationContext.xml" 
	todir="${project.build.outputDirectory}/META-INF/spring" overwrite="true"/>
<delete file="${project.build.outputDirectory}/applicationContext.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
```

```
 
```

 

参考：

1，[http://maven.apache.org/plugins/maven-antrun-plugin/](http://maven.apache.org/plugins/maven-antrun-plugin/)

2，[http://ant.apache.org/manual/index.html](http://ant.apache.org/manual/index.html)