Christian Rockrohr
Christian Rockrohr

Reputation: 1045

automatically created JAR File in parent target-directory with maven

I have a multi module java maven project. When I build the parent project, it runs smoothly through all the modules, compiles them and creates the jar files each in its own module directory.

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

I would prefer to get all jar files from one single directory, the parent target dir for example.

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

Is this somehow possible?

Cheers, Christian

Upvotes: 1

Views: 4390

Answers (1)

You could try the following (which is a slightly different version of 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>

There are many prefixes that are commonly used that you can read about from 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

Upvotes: 1

Related Questions