Maven copy方式列举

maven copy有很多种方法:

1.maven-antrun-plugin (使用ant复制)

 <build>
        <finalName>flex</finalName>
        <sourceDirectory>src</sourceDirectory>
        <outputDirectory>../monitorweb/src/main/webapp/topoview</outputDirectory>
        <plugins>
    
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                     <execution>
                         <phase>validate</phase>
                         <goals>
                             <goal>run</goal>
                         </goals>
                         <configuration>
                             <tasks>
                                 <echo message="*****copy LocalConnectionSender.html and LocalConnectionSender.swf to  ../monitorweb/src/main/webapp/topoview*****"/>
                                 <copy todir="../monitorweb/src/main/webapp/topoview" overwrite="true">
                                 <fileset dir="src/assets/dragapp"/>
                                 </copy>
                             </tasks>
                         </configuration>
                     </execution>
                    </executions>
            </plugin>
        </plugins>

    </build>

2.maven-dependency-plugin

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-installed</id>
            <phase>install</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>some-other-place</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

3.maven-jar-plugin

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            ...
            <configuration>
              <archive>
                <manifest>
                  <addClasspath>true</addClasspath>
                </manifest>
              </archive>
            </configuration>
            ...
          </plugin>
        </plugins>
      </build>
      ...
      <dependencies>
        <dependency>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
          <version>2.1</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.plexus</groupId>
          <artifactId>plexus-utils</artifactId>
          <version>1.1</version>
        </dependency>
      </dependencies>
      ...
    </project>

最后我使用了maven ant ,感觉它控制的比较细,上手也比较快。

原文地址:https://www.cnblogs.com/yangpigao/p/3156366.html