Dragon
Dragon

Reputation: 2481

Maven: how to change classes jar name in war?

I use archiveClasses and attachClasses in settings of maven-war-plugin in order module classes to be packed in jar.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven-war-plugin.version}</version>
    <configuration>
        <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
        <archiveClasses>true</archiveClasses>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>

But I'd like to change this .jar name. For example, war-classes.jar instead of module-war-1.0-SNAPSHOT.jar.

How can I do it if I can?

Upvotes: 2

Views: 1571

Answers (1)

ben75
ben75

Reputation: 28706

You can use to outputFileNameMapping to do some filename modification (I'm not it will suit your needs).

<configuration>
      <outputFileNameMapping>${artifactId}.jar</outputFileNameMapping>
  ...
</configuration>

The pattern you specify in outputFileNameMapping will be the file name of the jar containing all your code of your war artifact (only there if you also use <archiveClasses>true</archiveClasses> of course).

But additionally, this pattern will be appended to all you dependencies (with a dash as separator) so for instance log4j-4.16.jar will be named log4j-myWebApp.jar (assuming ${artifactId} is resolved to myWebApp and that you use this pattern ${artifactId}.jar)

Upvotes: 1

Related Questions