使用maven在父目标目录中自动创建JAR文件

时间:2013-12-27 15:33:09

标签: java maven

我有一个多模块java maven项目。当我构建父项目时,它可以顺利运行所有模块,编译它们并在每个模块目录中创建jar文件。

- parent
- module 1
-- target
--- mod1.jar
- modules 2
-- target
---mod2.jar

我更愿意从一个目录中获取所有jar文件,例如父目标目录。

- parent
-- target
--- mod1.jar
--- mod2.jar
- module 1
- module 1

这有可能吗?

干杯,基督徒

1 个答案:

答案 0 :(得分:1)

您可以尝试以下操作(this solution的版本略有不同):

<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>             
              <id>copy-artifact</id>
              <phase>package</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>../Main/target/dependencies</outputDirectory>-->  
                <!--CHANGE IS HERE -->
                <outputDirectory>${project.build.directory} </outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
</build>

您可以从here了解许多常用的前缀:

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix. This list is just an example of some commonly used elements. (deprecated: {pom.} prefix)

    ${project.build.directory} results in the path to your "target" directory, this is the same as ${pom.project.build.directory}
    ${project.build.outputDirectory} results in the path to your "target/classes" directory
    ${project.name}refers to the name of the project (deprecated: ${pom.name} ).
    ${project.version} refers to the version of the project (deprecated: or ${pom.version}).
    ${project.build.finalName} refers to the final name of the file created when the built project is packaged