将Maven模块项目目录的内容复制到另一个模块中

时间:2018-09-19 15:54:39

标签: maven maven-assembly-plugin

我想复制directorymodule maven项目的内容。 这是层次结构 enter image description here 我要将dist目录的内容复制到Tourism/Tourism-Services/src/main/webapp目录

为此,我尝试使用maven-assembly-plugin

这是相对pom.xml的摘录

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>./</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>cfg-main-resources</id>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                            <descriptor>${basedir}/src/main/angular5/tourism/assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

这是Assembly.xml文件的摘录

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>distribution</id>
    <formats>
        <format>dir</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <outputDirectory>./</outputDirectory>
            <directory>src/main/angular5/tourism/dist</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

问题是dist目录的内容复制到Tourism / Tourism-Web / target目录中。我想将此内容复制到Tourism/Tourism-Services/src/main/weapp目录中的另一个模块中。谢谢您的帮助

1 个答案:

答案 0 :(得分:1)

我成功配置了pom.xml。

这是Tourism-Web子模块中pom.xml的一部分

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>true</appendAssemblyId>
        </configuration>
            <executions>
                <execution>
                    <id>cfg-main-resources</id>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                            <descriptor>${basedir}/src/main/angular5/tourism/assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

这是汇编描述符文件的摘录

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>assembly</id>
<formats>
    <format>zip</format>
</formats>

<includeBaseDirectory>false</includeBaseDirectory>

<fileSets>
    <fileSet>
        <outputDirectory>./</outputDirectory>
        <directory>src/main/angular5/tourism/dist</directory>
        <includes>
            <include>**/*</include>
        </includes>
    </fileSet>
</fileSets>

这里是Tourism-Services子模块pom.xml的摘录

    <dependencies>
    <dependency>
        <groupId>tourism-guide</groupId>
        <artifactId>tourism-web</artifactId>
        <version>${project.version}</version>
        <classifier>assembly</classifier>
        <type>zip</type>
        <scope>compile</scope>
    </dependency>   
..................
's..................
    </dependencies>
<build>
    <!-- Set the name of the war, used as the context root when the app is 
        deployed -->
    <finalName>${project.artifactId}</finalName>

<plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
              <execution>
                  <id>unpack-angular-dist-resources</id>
                  <goals>
                      <goal>unpack-dependencies</goal>
                  </goals>
                  <phase>compile</phase>
                  <configuration>
                      <outputDirectory>${basedir}/src/main/webapp</outputDirectory>
                      <includeArtifactIds>tourism-web</includeArtifactIds>
                      <includeGroupIds>${project.groupId}</includeGroupIds>
                      <excludeTransitive>true</excludeTransitive>
                      <excludeTypes>pom</excludeTypes>
                      <scope>compile</scope>
                  </configuration>
              </execution>
          </executions>
      </plugin>
    </plugins>
</build>

感谢您阅读