[war打包]在maven-antrun-plugin复制更改了配置文件但是maven-war-plugin打包出来配置文件没变化(草稿)

本文详细介绍了一个Java Web项目如何通过Maven配置实现不同环境下的properties文件切换。具体包括pom.xml配置、profiles使用方法、资源文件过滤及排除策略等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言 &背景介绍

在某个java-web项目中,需要根据maven的profile的配置进行properties文件的切换,
例如,项目的配置文件结构如下:
这里写图片描述

在resources文件夹下面分别有profiles文件夹及conf文件夹【重点关注】,
profiles下面有三个环境,分别是dev,test,product,而conf的配置文件都是跟随开发人员选择的环境【dev,test,product】而改变的,假如选择的是product,那么构建以后conf下面的配置文件就会被product下面的四个文件替换掉。

重点说说env.properties的内容,作为替换成功与否的构建标准,注意,conf下面默认的配置文件是dev的,构建与否不会替换掉。
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

好了,几个环境下面的env文件内容说明完毕。

下面将构建配置文件pom内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.w2p</groupId>
    <artifactId>MicroWeb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <!--设置配置环境profile begin -->
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <package.environment>dev</package.environment>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <package.environment>test</package.environment>
            </properties>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <package.environment>product</package.environment>
            </properties>
        </profile>
    </profiles>
    <!--设置配置环境profile bend -->

    <!--好了,是不是经常发现pom文件一加一点东西idea的编译环境就会自动变化1.5版本的jdk??加上这个强行指定编译版本就没问题了。-->

    <build>
        <!--名字统一一下-->
        <finalName>${project.artifactId}</finalName>



        <plugins>




            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>


            <!--打包替换-->


            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <!--<phase>package</phase>-->

                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>

                                <!--<echo message="自动处理,下一步要删除该路径:${project.build.directory}/${project.build.finalName}/WEB-INF/classes/conf" level="debug"/>-->
                                <delete dir="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/conf"/>
                                <!--<copy todir="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/conf">-->
                                <!--<fileset dir="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/profiles/${package.environment}/"/>-->
                                <!--</copy>-->
                                <copy todir="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/conf">
                                    <fileset dir="src/main/resources/profiles/${package.environment}"/>
                                </copy>

                                <delete dir="${project.build.directory}/${project.build.finalName}/classes/conf"/>
                                <!--<copy todir="${project.build.directory}/${project.build.finalName}/classes/conf">-->
                                    <!--<fileset dir="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/profiles/${package.environment}/"/>-->
                                <!--</copy>-->
                                <copy todir="${project.build.directory}/${project.build.finalName}/classes/conf">
                                    <fileset dir="src/main/resources/profiles/${package.environment}"/>
                                </copy>

                                <!-- <delete file="./src/main/webapp/js/config.js" />   -->
                                <!--<move file="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/profiles/${package.environment}/**" tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/classes/conf/**"/>-->
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--打包文件替换end-->



            <!--war 打包 begin -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <!--
                      Exclude JCL and LOG4J since all logging should go through SLF4J.
                      Note that we're excluding log4j-<version>.jar but keeping
                      log4j-over-slf4j-<version>.jar
                    -->

                    <webXml>web\WEB-INF\web.xml</webXml>
                    <!--指定jsp、js、css的路劲  -->
                    <warSourceDirectory>web</warSourceDirectory>
                    <packagingExcludes>
                        WEB-INF/lib/commons-logging-*.jar,
                        %regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
                    </packagingExcludes>

                    <webResources>


                    </webResources>
                </configuration>
            </plugin>
            <!--war 打包 end -->





        </plugins>
    </build>


    <dependencies>

        <!--基础类库-->
        <dependency>
            <!--Group   net.funfunle-->
            <!--Name    baselib-->
            <groupId>net.funfunle</groupId>
            <artifactId>baselib</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <!--注意,这玩意会同时引用slf4j-api以及slf4j-log4j12,这两个是会冲突的。其中一个不引用了。-->
            <exclusions>
                <!--去除不用的依赖包-->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--app项目对应api项目 begin -->
        <dependency>
            <groupId>net.w2p</groupId>
            <artifactId>MicroBaseApi</artifactId>
            <version>1.0-SNAPSHOT</version>
            <!--注意,这玩意会同时引用slf4j-api以及slf4j-log4j12,这两个是会冲突的。其中一个不引用了。-->
            <exclusions>
                <!--去除不用的依赖包-->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--app项目对应api项目 end-->
        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>



        <!-- Servlet web -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>



        <!--七牛 begin -->

        <dependency>
            <groupId>com.qiniu</groupId>
            <artifactId>qiniu-java-sdk</artifactId>
            <version>[7.2.0, 7.2.99]</version>
        </dependency>
        <!--七牛 end -->

        <!--apache commons 类库 begin -->
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <!--apache commons 类库 end -->


    </dependencies>

</project>

好了,idea上面的界面如下:
这里写图片描述

接下来将分别打包test及product环境。

test环境打包

点击clean及package之后,构建内容如下:
这里写图片描述

这里写图片描述

env文件内容如下:
这里写图片描述

而war文件中,

这里写图片描述
env内容如下:

这里写图片描述

dev。。。。。。。

推测:maven是先进行war打包,然后antrun才进行替换的。所以替换无效。

相关资料参考

请看看链接:

Maven: antrun-plugin vs war-plugin

这里写图片描述

Maven-antrun-plugin modify artifact before war is packaged

<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>
           <-- JAR was modified in here -->
                </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>

Maven profiles: maven-antrun-plugin & maven-war-plugin interaction

Maven profiles: maven-antrun-plugin & maven-war-plugin interaction
Ask Question
up vote
0
down vote
favorite
I have a Spring framework project with the following three files in src/main/webapp/WEB-INF:

project.propterties
project-servlet.xml
project-security.xml
I am trying to use maven profiles as follows to 'inject' the above mentioned files in the case of a prod build:

        <profile>
        <id>prod-build</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <target>
                                    <delete
                                        file="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" />
                                    <copy file="src/main/config/prod/project.properties"
                                        tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/project.properties" />
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources/prod</directory>
                </resource>
            </resources>
        </build>
    </profile>
The problem is by the time maven-antrun-plugin gets a chance to run, the war has already been packaged. The ant <target> does run and makes appropriate changes, but too late.

The command line:

$ mvn -Pprod-build clean install
mvn output:

    [INFO] --- maven-antrun-plugin:1.7:run (default) @ FocusMVN ---
[INFO] Executing tasks

main:
     [copy] Copying 1 file to J:\work\workspace\FocusMVN\target\myproject\WEB-INF
[INFO] Executed tasks
[INFO] 
[INFO] --- maven-war-plugin:2.3:war (default-war) @ FocusMVN ---
[INFO] Packaging webapp
[INFO] Assembling webapp [FocusMVN] in [J:\work\workspace\FocusMVN\target\myproject]
[INFO] Processing war project
[INFO] Copying webapp resources [J:\work\workspace\FocusMVN\src\main\webapp]
[INFO] Webapp assembled in [3198 msecs]
[INFO] Building war: J:\work\workspace\FocusMVN\target\myproject.war
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ FocusMVN ---
[INFO] Installing J:\work\workspace\FocusMVN\target\myproject.war to C:\Users\mansoork\.m2\repository\ca\utoronto\med\dc\FocusMVN\0.0.1-SNAPSHOT\FocusMVN-0.0.1-SNAPSHOT.war
[INFO] Installing J:\work\workspace\FocusMVN\pom.xml to C:\Users\mansoork\.m2\repository\ca\utoronto\med\dc\FocusMVN\0.0.1-SNAPSHOT\FocusMVN-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Any pointers will be greatly appreciated.

maven maven-profiles maven-antrun-plugin
shareimprove this question
edited Feb 5 '13 at 15:15
asked Feb 5 '13 at 14:42

kmansoor
1,47253567
1
You can bind antrun to prepare-package phase instead of package one. – Andrew Logvinov Feb 5 '13 at 14:45
@Andrew Logvinov Thanks; It doesn't appear to make a difference; I have updated my question with mvn output, can you please take a look? – kmansoor Feb 5 '13 at 15:16 
Which maven version do you use? – khmarbaise Feb 7 '13 at 12:30
@khmarbaise, I'm using Maven 3.0.4 – kmansoor Feb 7 '13 at 16:27
add a comment
2 Answers
active oldest votes
up vote
0
down vote
accepted
Did you note this line

[INFO] Copying webapp resources [J:\work\workspace\FocusMVN\src\main\webapp]
What's going on ?

The maven-war-plugin copy the content of src/main/webapp (which contains your dev project.properties) to the war. And while doing this it replace the one just copied by the ant task.

What you can try is to exclude the project.properties from the fileset copied by the maven-war-plugin (since it was already copied by your ant task.)

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>     
    <configuration>
       <warSourceExcludes>WEB-INF/project.propterties</warSourceExcludes>
    </configuration>
</plugin>
reference

shareimprove this answer
edited Feb 5 '13 at 17:18
answered Feb 5 '13 at 16:05

ben75
22.4k664110
You mean warSourceExcludes? – kmansoor Feb 5 '13 at 17:05
@kmansoor right... just updated my post – ben75 Feb 5 '13 at 17:17
add a comment

up vote
1
down vote
In the phase use prepare-package instead of package.

Instead of maven-antrun-plugin try to use copy-maven-plugin

<plugin>
            <groupId>com.github.goldin</groupId>
            <artifactId>copy-maven-plugin</artifactId>
            <version>0.2.5</version>
            <executions>
                <execution>
                    <id>create-archive</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                            <targetPath>${basedir}/target/</targetPath>
                            <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                            <includes>
                                <include>**/project*</include>
                            </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
shareimprove this answer
edited Feb 5 '13 at 16:04
answered Feb 5 '13 at 14:48

Carlos Rodrigues
1363
+1: You beat me to it! :) In addition, have a look at the list of phases described here: sonatype.com/books/mvnref-book/reference/… . – carlspring Feb 5 '13 at 15:07
@Carlos Rodrigues thanks for your comment. I have updated my question with mvn output, using prepare-package didn't help either. Can you please take a look? Thank you. – kmansoor Feb 5 '13 at 15:17 
add a comment
Your Answer


Post Your Answer
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Not the answer you're looking for? Browse other questions tagged maven maven-profiles maven-antrun-plugin or ask your own question.
asked

5 years, 5 months ago

viewed

3,898 times

active

5 years, 5 months ago

Looking for a job?
Cybersecurity Software Engineer
CyleraNew York, NY
$120K - $150KREMOTE
credis
Project Manager
EPAMShenzhen, China
RELOCATION
project-managementlifecycle
Helpdesk Support
AsiaInspection.comShenzhen, China
$16K - $20KRELOCATION
lotus-noteslotus-domino
Be one of the first applicants
HTML5 / Web Designer (React/Redux Pref.)
Core DataNo office location
REMOTE
reactjsuser-interface
Visit Chat
Related
7
How to bind maven antrun plugin to the clean phase
20
Maven: how to get a war package with resources copied in WEB-INF?
5
Files got overwritten in maven project when building a war
4
How to call maven-antrun-plugin target without attach execution to a maven phase ?
5
Calling foreach in maven-antrun-plugin
3
maven overlay of exploded war: excluding items from exploded war
4
Appengine skeleton not running
2
Maven Dependency Plugin not copying libraries to war file
0
maven-resources-plugin + profiles
1
Overlays are duplicated on classpath when war runs with maven-jetty-plugin
Hot Network Questions
I want a choice about starting a Desktop system or a Server system
Why does one person have lots of stamina and another doesn't?
Delete content of file but keep name and hierarchy
How can I write about historical realities that readers mistakenly believe are unrealistic?
Anagrams: From Food to Food
more hot questions

Maven: excluding java files in compilation

Maven: excluding java files in compilation
Ask Question
up vote
34
down vote
favorite
12
I have a folder of java sources which I wish to exclude from the compilation.

My folder is under qa/apitests/src/main/java/api/test/omi.

I added the following entry in the pom.xml under qa/bamtests but it didn't help. Is there an entry in addition I need to make?

   <build>
     <resources>
       <resource>
         <directory>src/main/java</directory>
         <includes>
           <include>**/*.properties</include>
           <include>**/*.xml</include>
           <include>**/*.xsd</include>
           <include>**/*.csv</include>
         </includes>
         <excludes>
<exclude>src/main/java/api/test/omi</exclude>
         </excludes>
       </resource>
</build>
maven
shareimprove this question
edited Jul 29 '13 at 10:03
user1907906
asked Jul 29 '13 at 9:53

constantlearner
2,91433151
Location for properties is src/main/resources for test properties src/test/resources. – khmarbaise Jul 29 '13 at 9:59
How does your project in qa/bamtests even find the sources in qa/apitests? – user1907906 Jul 29 '13 at 10:04
what about using the same pattern for excludes: <exclude>**/test/omi/**</exclude> – boskop Jul 29 '13 at 10:09
a bit off topic: your way to organize resources is just a mess. You should put it in src/main/resources (or create other directories under src/main/ ) to organize your different kind of resources – Adrian Shum Aug 12 '13 at 3:32
Read Stefan's answer about the need to remove src/main/java/ from the path! – xverges Jan 23 '15 at 15:31 
add a comment
5 Answers
active oldest votes
up vote
45
down vote
accepted
Use the Maven Compiler Plugin.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <excludes>
      <exclude>**/api/test/omi/*.java</exclude>
    </excludes>
  </configuration>
</plugin>
shareimprove this answer
edited Nov 28 '16 at 16:35
community wiki
2 revs, 2 users 96%
user1907906
What does the two leading * stand for ? – Patrizio Bertoni Jun 11 '15 at 14:40
2
The ** mean 'any directories'. – user1907906 Jun 11 '15 at 14:41
2
This answer didn't work for me. Look at this stackoverflow.com/a/19713000/358013 – blueskin Sep 3 '15 at 17:17
4
For me it did not work either, I had to remove src/main/java part ... Looks like a relative path issue. Can someone please explain in detail? – Soumya Kanti Sep 7 '15 at 12:03
1
To exclude tests, see @michal-kordas 's answer on stackoverflow.com/a/32531306/517134 it worked for me – Yusuf K. Feb 8 '17 at 7:48 
show 1 more comment

Maven - exclude folder from build

Ask Question
up vote
23
down vote
favorite
4
Trying to exlcude a folder src/main/resources/scripts/ from my build but the following does not work:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>src/main/resources/scripts/</exclude>
            </excludes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <excludes>
                    <exclude>src/main/resources/scripts/</exclude>
                </excludes>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Any ideas?

maven maven-compiler-plugin
shareimprove this question
asked Aug 12 '14 at 11:11

Cheetah
5,2772469133
add a comment
3 Answers
active oldest votes
up vote
40
down vote
accepted
Instead try:

<exclude>scripts/**</exclude>
The exclude is based on directory, so your construction would exclude

src/main/resources/src/main/resources/scripts
shareimprove this answer
answered Aug 12 '14 at 11:16

Robert Scholte
7,58521930
2
Thanks for the suggestion but this doesn't seem to work for me. – Cheetah Aug 12 '14 at 11:18
2
Did you do a mvn clean first? Btw, it has no effect on the manven-compiler-plugin, which only compiles .java files. The maven-resources-plugin is responsible for copying these files to the classpath. – Robert Scholte Aug 12 '14 at 11:21
I did do a mvn clean first... – Cheetah Aug 12 '14 at 11:26
4
maven.apache.org/plugins/maven-resources-plugin/examples/… gives you proper examples. ** only matches the directories, in case of files, I'd expect it to be scripts/**/* – Robert Scholte Aug 12 '14 at 12:29
Again, no joy. I am doing a mvn clean, then a mvn compile. – Cheetah Aug 12 '14 at 14:06
show 2 more comments

好了,我们将,war的执行阶段改为:deploy,又会如何呢?
试一试。

文章废弃

因为核心是要war部署多环境,不过已经找到方案了:

Maven 的 Web 项目使用 war 插件针对不同环境打包

所以经过整理,最后的代码是:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.w2p</groupId>
    <artifactId>MicroWeb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>




    <!--设置配置环境profile begin -->
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <package.environment>dev</package.environment>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <package.environment>test</package.environment>
            </properties>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <package.environment>product</package.environment>
            </properties>
        </profile>
    </profiles>
    <!--设置配置环境profile bend -->

    <!--好了,是不是经常发现pom文件一加一点东西idea的编译环境就会自动变化1.5版本的jdk??加上这个强行指定编译版本就没问题了。-->

    <build>
        <!--名字统一一下-->
        <finalName>${project.artifactId}</finalName>


        <!-- 主资源目录 -->
        <resources>
            <resource>
                <!-- 设置主资源目录 -->
                <directory>src/main/resources</directory>
                <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,是否对主资源目录开启资源过滤 -->
                <filtering>true</filtering>
                <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,只处理如下配置中包含的资源类型 -->
                <!-- 包括文件 -->
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,不处理如下配置中包含的资源类型(剔除下如下配置中包含的资源类型)-->
                <!-- 排除文件,这些文件打包的时候应该被排除 -->
                <excludes>
                    <exclude>profiles/dev/*.properties</exclude>
                    <exclude>profiles/test/*.properties</exclude>
                    <exclude>profiles/product/*.properties</exclude>
                    <exclude>conf/*.properties</exclude>
                </excludes>
            </resource>
        </resources>



        <plugins>




            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>

                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>


            <!--打包替换-->






            <!--打包文件替换end-->



            <!--war 打包 begin -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>

                <configuration>

                    <!--
                      Exclude JCL and LOG4J since all logging should go through SLF4J.
                      Note that we're excluding log4j-<version>.jar but keeping
                      log4j-over-slf4j-<version>.jar
                    -->

                    <webXml>web\WEB-INF\web.xml</webXml>
                    <!--指定jsp、js、css的路劲  -->
                    <warSourceDirectory>web</warSourceDirectory>
                    <packagingExcludes>
                        WEB-INF/lib/commons-logging-*.jar,
                        %regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
                    </packagingExcludes>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/profiles/${package.environment}</directory>
                            <targetPath>WEB-INF/classes/conf</targetPath>
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                </configuration>

        </plugin>
            <!--war 打包 end -->





        </plugins>
    </build>


    <dependencies>

        <!--基础类库-->
        <dependency>
            <!--Group   net.funfunle-->
            <!--Name    baselib-->
            <groupId>net.funfunle</groupId>
            <artifactId>baselib</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <!--注意,这玩意会同时引用slf4j-api以及slf4j-log4j12,这两个是会冲突的。其中一个不引用了。-->
            <exclusions>
                <!--去除不用的依赖包-->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--app项目对应api项目 begin -->
        <dependency>
            <groupId>net.w2p</groupId>
            <artifactId>MicroBaseApi</artifactId>
            <version>1.0-SNAPSHOT</version>
            <!--注意,这玩意会同时引用slf4j-api以及slf4j-log4j12,这两个是会冲突的。其中一个不引用了。-->
            <exclusions>
                <!--去除不用的依赖包-->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--app项目对应api项目 end-->
        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>



        <!-- Servlet web -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>



        <!--七牛 begin -->

        <dependency>
            <groupId>com.qiniu</groupId>
            <artifactId>qiniu-java-sdk</artifactId>
            <version>[7.2.0, 7.2.99]</version>
        </dependency>
        <!--七牛 end -->

        <!--apache commons 类库 begin -->
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <!--apache commons 类库 end -->


    </dependencies>

</project>

而且,打包的结果是:

这里写图片描述

完满解决

maven-antrun-plugin是一个Maven构建工具中的插件,它允许您在Maven构建期间运行Ant任务。通过maven-antrun-plugin,您可以在Maven构建期间执行任何Ant任务,这使得您可以利用Ant的强大功能来扩展Maven构建。例如,您可以使用maven-antrun-plugin运行任何Ant任务,例如复制文件,打包文件,运行测试等等。是的,您的理解是正确的。maven-antrun-pluginMaven 构建工具中的一个插件,它可以将 Ant 任务嵌入到 Maven 构建过程中,从而扩展构建的功能。通过 maven-antrun-plugin,您可以在 Maven 构建期间运行任何 Ant 任务,如编译 Java 代码、运行测试、生成文档、打包文件等等。这个插件可以帮助您利用 Ant 的强大功能来扩展 Maven 的构建能力,从而更好地管理和构建项目。 是的,您的理解是正确的。maven-antrun-pluginMaven 构建工具中的一个插件,它可以将 Ant 任务嵌入到 Maven 构建过程中,从而扩展构建的功能。通过 maven-antrun-plugin,您可以在 Maven 构建期间运行任何 Ant 任务,如编译 Java 代码、运行测试、生成文档、打包文件等等。这个插件可以帮助您利用 Ant 的强大功能来扩展 Maven 的构建能力,从而更好地管理和构建项目。错,您的理解是正确的。maven-antrun-plugin是一个Maven构建工具中的插件,它允许您在Maven构建期间运行Ant任务。通过maven-antrun-plugin,您可以在Maven构建期间执行任何Ant任务,这使得您可以利用Ant的强大功能来扩展Maven构建。例如,您可以使用maven-antrun-plugin运行任何Ant任务,例如复制文件,打包文件,运行测试等等。是的,您的理解是正确的。maven-antrun-pluginMaven 构建工具中的一个插件,它可以将 Ant 任务嵌入到 Maven 构建过程中,从而扩展构建的功能。通过 maven-antrun-plugin,您可以在 Maven 构建期间运行任何 Ant 任务,如编译 Java 代码、运行测试、生成文档、打包文件等等。这个插件可以帮助您利用 Ant 的强大功能来扩展 Maven 的构建能力,从而更好地管理和构建项目。 是的,您的理解是正确的。maven-antrun-plugin是一个Maven构建工具中的插件,它允许您在Maven构建期间运行Ant任务。通过maven-antrun-plugin,您可以在Maven构建期间执行任何Ant任务,这使得您可以利用Ant的强大功能来扩展Maven构建。例如,您可以使用maven-antrun-plugin运行任何Ant任务,例如复制文件,打包文件,运行测试等等。这个插件可以帮助您利用 Ant 的强大功能来扩展 Maven 的构建能力,从而更好地管理和构建项目。是的,您的理解是正确的。maven-antrun-plugin是一个Maven构建工具中的插件,它允许您在Maven构建期间运行Ant任务。通过maven-antrun-plugin,您可以在Maven构建期间执行任何Ant任务,这使得您可以利用Ant的强大功能来扩展Maven构建。例如,您可以使用maven-antrun-plugin运行任何Ant任务,例如复制文件,打包文件,运行测试等等。这个插件可以帮助您利用 Ant 的强大功能来扩展 Maven 的构建能力,从而更好地管理和构建项目。maven-antrun-plugin是一个Maven插件,它允许您在Maven构建过程中运行Ant任务。Ant是另一个构建工具,它使用XML文件来定义构建过程。通过maven-antrun-plugin,您可以将Ant任务集成到Maven构建中,并利用Maven的依赖管理和构建生命周期来控制Ant任务的执行顺序和参数传递。使用maven-antrun-plugin,您可以更方便地管理复杂的构建过程,并将其与其他Maven插件和构建功能集成。maven-antrun-pluginMaven构建工具中的一个插件,用于在构建过程中运行Ant任务。Ant是一种Java语言编写的自动化构建工具,可以执行一系列预定义的任务,例如编译Java代码、打包文件等等。maven-antrun-plugin允许将Ant任务集成到Maven构建过程中,以实现更灵活和定制化的构建过程。可以通过配置pom.xml文件来定义需要执行的Ant任务和参数。maven-antrun-plugin 是一个Maven构建工具的插件,它可以通过Ant任务在Maven构建过程中执行一些额外的操作。具体来说,maven-antrun-plugin 允许您在构建期间运行Ant任务,例如编译Java源代码、生成文档或运行测试。此外,它还可以用于执行其他一些常见的构建任务,例如文件复制、文件移动、目录创建等等。因此,maven-antrun-plugin 可以让您在Maven构建过程中更加灵活地完成各种构建任务。maven-antrun-plugin是一个Maven插件,它允许你在Maven构建过程中使用Ant任务。它允许你在构建过程中使用Ant任务来完成各种任务,例如复制文件、压缩文件、运行命令等。它可以通过在Maven项目的pom.xml文件中配置来使用。使用maven-antrun-plugin,可以很容易地将Ant任务集成到Maven构建过程中,以便更好地管理和维护你的项目。maven-antrun-pluginMaven构建工具中的一个插件,它允许开发者在Maven构建过程中使用Ant任务。使用maven-antrun-plugin,开发者可以在Maven的生命周期中执行Ant脚本来完成一些特定的任务,例如复制文件、压缩文件等。这个插件可以为Maven构建提供更多的灵活性和功能扩展。maven-antrun-plugin是一个Maven插件,它允许您在构建期间运行Apache Ant任务。它可以通过Maven的构建生命周期来运行Ant任务,从而实现自定义构建过程的自动化。使用maven-antrun-plugin,您可以在Maven构建期间运行任何Ant任务,这些任务可以在Maven项目中执行任何操作,例如编译代码、复制文件、运行测试等。 我不太熟悉maven-antrun-plugin,但是我可以尝试提供一些帮助。maven-antrun-pluginMaven 中的一个插件,用于在构建过程中执行 Ant 任务。通过该插件,可以在 Maven 构建过程中使用 Ant 构建脚本,执行一些与构建相关的自定义任务,如编译、测试、打包等。可以将 Ant 任务与 Maven 生命周期阶段关联起来,实现更加灵活和精细的构建过程控制。maven-antrun-plugin 的使用需要在 Maven 项目的 pom.xml 文件中进行配置。maven-antrun-pluginMaven构建工具中的一个插件,用于在构建过程中执行Ant任务。Ant是一个Java构建工具,可以通过XML文件来描述构建过程中需要执行的任务和依赖关系。使用maven-antrun-plugin插件可以将Ant任务集成到Maven构建过程中,从而实现更复杂的构建过程和自动化流程。例如,可以使用maven-antrun-plugin插件来编译、打包、部署应用程序或者执行其他一些自定义任务。maven-antrun-pluginMaven 构建工具中的一个插件,它允许用户在构建过程中使用 Ant 任务来完成额外的构建工作。该插件可以在构建周期的不同阶段调用 Ant 任务,例如在编译之前或打包之后。使用 maven-antrun-plugin 可以扩展 Maven 的构建功能,使得用户可以在构建过程中使用 Ant 提供的丰富的任务库来完成各种自定义构建任务。maven-antrun-pluginMaven中一个非常有用的插件,它可以将Ant构建脚本整合到Maven构建过程中,使得开发者可以在Maven构建的过程中执行Ant脚本任务。maven-antrun-plugin可以帮助开发者执行各种任务,如编译代码、打包、压缩、拷贝文件等等。此插件提供了很多可配置的选项,例如执行Ant脚本的目标、Ant脚本文件的位置以及Ant属性等等。在Maven构建中使用maven-antrun-plugin可以帮助开发者更加高效地完成各种构建任务。maven-antrun-plugin是一个Maven插件,可以让你在Maven构建过程中执行Ant任务。Ant是另一个构建工具,它使用XML来描述构建过程。使用maven-antrun-plugin,你可以在Maven项目中使用Ant任务来完成某些特定的构建任务,从而扩展Maven构建的功能。该插件可以在Maven项目的pom.xml文件中配置和使用。maven-antrun-plugin是一个Maven构建工具的插件,它可以让你在Maven构建过程中执行Ant任务。Ant是一个基于Java的自动化构建工具,它可以用来执行各种各样的构建任务,例如编译代码、打包文件、运行测试等等。通过maven-antrun-plugin插件,你可以在Maven构建过程中利用Ant的强大功能,完成更加复杂的构建任务。 我知道 maven-antrun-plugin 是一个基于 Apache Ant 的Maven插件,可以在Maven项目中运行Ant脚本。maven-antrun-pluginMaven 构建工具中的一个插件,它可以通过 Ant 构建脚本的方式扩展 Maven 的构建过程。通过该插件,可以在 Maven 构建过程中运行 Ant 脚本,完成一些 Maven 本身无法实现的构建任务。例如,可以使用 maven-antrun-plugin 执行一些文件操作、压缩和解压缩、生成和解析 XML 文件等等操作。该插件非常灵活,可以通过配置文件定义不同的 Ant 任务,从而满足各种不同的构建需求。 我可以解释maven-antrun-plugin的用途:AntRun插件可以在Maven构建过程中调用Ant任务,从而实现在Maven构建中使用Ant任务的非常有用的功能。 很高兴为你服务。Maven-Antrun-Plugin是Apache Maven中的一个插件,可以用来运行Apache Ant任务。maven-antrun-pluginMaven构建工具中的一个插件,它允许开发人员在Maven构建过程中执行Ant任务。使用maven-antrun-plugin可以在构建过程中实现一些自定义的操作,例如文件复制、文本替换、压缩文件等。它的配置也相对简单,可以通过指定Ant任务的xml文件或直接在pom.xml中编写Ant任务来完成所需操作。maven-antrun-plugin 是一个用于 Maven 构建工具的插件,它允许开发者在构建过程中运行 Ant 任务。Ant 是另一个流行的构建工具,它可以用于编译、打包和部署 Java 项目。maven-antrun-plugin 提供了一种方便的方法来集成 Ant 任务到 Maven 构建中,使得开发者可以使用 Ant 的强大功能来增强他们的 Maven 构建过程。maven-antrun-plugin是一个Maven插件,可以让你在Maven构建过程中使用Ant任务。Ant是一种构建工具,可以用XML文件描述构建过程中的任务。maven-antrun-plugin可以让你在Maven构建中执行Ant任务,比如编译Java代码、打包、测试等等。通过maven-antrun-plugin,你可以充分利用Ant的强大功能,并且将Ant任务和Maven构建过程集成起来,更加方便管理和维护你的项目。maven-antrun-plugin是一个Maven构建工具的插件,它使用Ant任务来执行一些额外的构建操作。它可以用来执行一些自定义的Ant任务,比如复制文件、压缩文件、运行脚本等等。使用maven-antrun-plugin可以方便地将这些操作集成到Maven构建过程中,使得整个构建过程更加自动化和高效。maven-antrun-pluginMaven的一个插件,用于在Maven构建过程中执行Ant任务。Ant是一种Java编写的自动化构建工具,它使用XML文件来描述构建过程中需要执行的任务。使用maven-antrun-plugin插件,开发人员可以在Maven构建过程中轻松地使用Ant任务来执行一些特定的操作,例如生成Java类、打包文件等。同时,该插件也支持执行内联的Ant脚本和外部的Ant构建文件。maven-antrun-plugin是一个Maven插件,它允许您在Maven构建期间执行Ant任务。Ant是一个Java库,用于自动化构建过程中的任务,如编译、测试和打包。使用maven-antrun-plugin,您可以在Maven构建期间轻松地执行Ant任务,从而实现更复杂的构建过程。该插件还允许您在Ant和Maven之间传递属性和文件,以便更灵活地控制构建过程。maven-antrun-plugin是一个Maven插件,可以使用Ant任务执行特定的构建操作。该插件允许您在Maven构建过程中使用Ant任务,以满足特定的构建需求。这个插件通常被用来执行一些额外的自定义构建脚本,比如文件拷贝、文件重命名、文件压缩、XML文件处理等。使用maven-antrun-plugin可以将Ant任务集成到Maven的构建过程中,以便在构建过程中使用Ant提供的强大功能来完成额外的构建任务。maven-antrun-pluginMaven构建工具中的一个插件,它可以让开发人员在Maven构建过程中使用Apache Ant的任务。Ant是一个基于XML的构建工具,它提供了一种简单的方式来管理和执行项目构建过程中的任务和操作。使用maven-antrun-plugin插件,开发人员可以在Maven构建过程中使用Ant任务,从而更好地管理和控制项目的构建。maven-antrun-plugin是一个Maven构建工具的插件,它允许开发人员在Maven构建期间运行Ant任务。Ant是一个Java构建工具,它提供了一组任务来处理文件、编译代码、运行测试等。使用maven-antrun-plugin插件可以将Ant任务与Maven构建集成,从而实现更多的构建自动化和定制化需求。在使用maven-antrun-plugin时,需要在pom.xml文件中配置插件及其参数,以便在Maven构建期间正确地执行所需的Ant任务。maven-antrun-pluginMaven中的一个插件,它可以让开发人员在Maven构建过程中使用Ant任务。它的作用是在Maven构建过程中运行指定的Ant任务,从而对项目进行各种自定义操作,例如复制文件、生成文档、运行测试等等。使用maven-antrun-plugin可以方便地将Ant任务与Maven构建过程结合起来,实现更灵活的项目构建和自动化。maven-antrun-plugin是一个Maven插件,它允许您在Maven构建过程中运行Ant任务。通过使用此插件,您可以在Maven构建期间执行任意数量的Ant任务。这可以用于许多不同的场景,例如自定义构建步骤,生成文档,运行测试等。使用maven-antrun-plugin可以让您更好地控制Maven构建,并将Ant任务与您的构建集成在一起。maven-antrun-pluginMaven 的一个插件,它可以让开发者在 Maven 构建过程中执行 Ant 任务。这个插件提供了一种在 Maven 构建中集成 Ant 构建的方式,可以方便地在 Maven 的生命周期中运行 Ant 任务,比如编译、测试、打包、部署等。使用 maven-antrun-plugin 可以让开发者更加灵活地控制 Maven 构建过程,实现更多定制化的需求。maven-antrun-plugin是一个Maven构建工具中的插件,用于在构建过程中执行Ant任务。Ant是一个流行的Java构建工具,它使用XML描述构建过程中的任务和依赖关系。maven-antrun-plugin允许您在Maven构建期间使用Ant任务来执行各种操作,如复制文件、运行命令、生成文档等。这个插件可以帮助您轻松地将Ant任务整合到Maven构建中,并使构建过程更加灵活和定制化。maven-antrun-plugin是一个Maven插件,它可以将Apache Ant构建脚本与Maven构建过程集成起来。使用maven-antrun-plugin,您可以在Maven项目中使用Ant任务来执行各种构建任务,例如编译代码、运行测试、打包项目等。该插件提供了丰富的配置选项,使得您可以轻松地配置和执行Ant任务,并将其集成到Maven构建过程中。maven-antrun-pluginMaven构建工具的一个插件,它允许您在Maven构建过程中执行Ant任务。Ant是一个流行的Java构建工具,可以用于编译代码、运行测试、打包等。通过maven-antrun-plugin插件,您可以在Maven构建中使用Ant任务来完成各种构建任务,从而使构建过程更加灵活和定制化。maven-antrun-plugin是一个Apache Maven插件,它允许在构建过程中运行Ant任务。通过使用maven-antrun-plugin,可以使用Ant的强大功能来完成各种构建任务,如复制文件、压缩文件、运行测试等。此外,maven-antrun-plugin还允许您使用Ant的自定义任务和其他功能来扩展构建过程,以满足特定的需求。Maven Antrun PluginMaven 中一个非常有用的插件,它允许你在 Maven 构建过程中执行 Ant 任务。 使用 Maven Antrun Plugin,你可以通过编写 Ant 脚本来完成诸如文件拷贝、压缩、解压缩、目录创建等构建任务。这些任务可以在 Maven 构建的各个阶段执行,比如在编译前或者打包后。 要使用 Maven Antrun Plugin,你需要在 pom.xml 文件中添加如下配置: ``` <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>compile</phase> <configuration> <tasks> <!-- 在这里编写 Ant 任务 --> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` 其中,`<phase>` 指定了在 Maven 构建过程中的哪个阶段执行该插件,`<tasks>` 中编写 Ant 任务。 例如,要在编译前执行一个 Ant 任务,可以将 `<phase>` 设置为 `compile`,然后在 `<tasks>` 中编写 Ant 任务。执行 `mvn compile` 命令时,Maven 会自动调用 Maven Antrun Plugin 插件,执行其中的 Ant 任务。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值