Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the actual output file name from maven

Tags:

maven

ant

I try to configure the maven ant plugin to copy the built artifact to a custom location:

<plugins>
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>install</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>

            <copy verbose="true" 
              file="target/${project.build.finalName}.${project.packaging}"
              tofile="${user.home}/tmp/test/${project.build.finalName}.${project.packaging}"/>

          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

This works fine, as long as the packaging is one of the standard ones... but if the packaging of the project is "bundle" (which generates a .jar), then the ${project.packaging} variable is "bundle" and the actual file ends with ".jar" = the copy fails.

How can I get the "real" name of the file that is put into the output directory?

like image 282
Tomas F Avatar asked Dec 13 '22 01:12

Tomas F


2 Answers

In ant build.xml using:

${project.build.directory}/${project.artifactId}-${project.version}.jar
like image 136
qxo Avatar answered Dec 24 '22 10:12

qxo


There is no way to do that reliably. For example, a POM can have several artifacts as result (binary JAR, sources JAR, test binary JAR, test sources JAR). Which one of them is the correct one to copy?

Possible solutions:

  1. Replace ${project.packaging} with jar. Should work in most cases.
  2. Use a file set instead of a hard coded file name to let Ant figure out the names based on patterns.
like image 27
Aaron Digulla Avatar answered Dec 24 '22 09:12

Aaron Digulla