---
title: "Maven定制部署到本地容器"
author: "juncke"
date: "2012-12-19T17:15:49Z"
tags: ["Deploy", "maven", "部署", "项目管理"]
categories: ["研发管理"]
slug: "maven"
draft: false
lastmod: "2012-12-19T17:21:56Z"
id: 1750530
url: "https://juncke.iteye.com/blog/1750530"
---

# Maven定制部署到本地容器

执行步骤：

1. Maven先使用maven-dependency-plugin将依懒包copy到dependency目录。
2. 用maven-antrun-plugin将package之后的目标文件和dependency目录下的文件copy到指定目录(如tomcat,jboss的deploy目录)。

注：根据需要替换deploy目录,我的是 d:/jboss/deploy

plugins配置

```
       <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo message="ant message echo" />
                                <echo
                                    message="packageName:${project.build.directory}\${project.build.finalName}.${project.packaging}" />
                                <copy todir="d:/jboss/deploy">
                                    <fileset dir="${project.build.directory}">
                                        <include name="${project.build.finalName}.${project.packaging}" />
                                    </fileset>
                                    <fileset dir="${project.build.directory}/dependency">
                                        <include name="*.jar" />
                                    </fileset>
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
```