50

I have a project with 5 modules in maven. Right now, when I do a "mvn clean install", it generates an ear containing the two jars, one war and one sar from the other modules.

All the file names contain the version, e.g., projectx-ear-2.0.0.ear, projectx-client-2.0.0.jar, etc.

I need to rename one of the jars and the final ear to omit the version in the file name. It should look like this:

projectx-ear.ear
|
+-- projectx-client.jar
|
+-- projectx-misc-2.0.0.jar
|
+-- projectx-sar-2.0.0.sar
|
\-- projectx-web-2.0.0.web

Right now I'm using the following plugins to build: maven-compiler-plugin and maven-release-plugin

What would be the best way to achieve the results I expect?

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Bani
  • 1,149
  • 2
  • 10
  • 17

3 Answers3

117

You can achieve this by specifying the finalName property in your pom like this:

<build>
    <finalName>${project.artifactId}</finalName>
</build>
Péter Török
  • 114,404
  • 31
  • 268
  • 329
23

In your ear module, you can either use the project.build.finalName element or you can configure the maven-ear-plugin which supports a finalName optional parameter. And to configure the final name of a bundled jar, you'll need to define a jarModule and to set the bundleFileName property for it.

The final configuration might looks something like that (I'll demonstrate how to set the the final ear name in the plugin configuration here):

<project>
  [...]
  <dependencies>
    <dependency>
      <groupId>yourgroupid</groupId>
      <artifactId>projectx-client</artifactId>
      <version>2.0.0</version><!-- not mandatory if inherited -->
    </dependency>
    [...]
  </dependencies>
  [...]  
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <finalName>projectx-ear</finalName>
          <modules>
            <jarModule>
              <groupId>yourgroupid</groupId>
              <artifactId>projectx-client</artifactId>
              <bundleFileName>anotherName.jar</bundleFileName>
            </jarModule>
          </modules>
        </configuration>
      </plugin>
      [...]
</project>
Saurabh
  • 71,488
  • 40
  • 181
  • 244
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 3
    As of now, later versions of the plugin (I am using 2.6) allows you to specify inside `` a `no-version` that deletes the version number of your modules (so you do not have to define each of them). The ear name is not affected by this, though. – SJuan76 Jul 13 '16 at 13:17
2

Point one : single JAR/WAR.

To create it without version number in name, in pom.xml simply add the code:

<build>
  <finalName>${project.artifactId}</finalName>
</build>

So, if you compile, for example projectx_misc, you get projectx_misc.jar .

What happens to me? When I compile the same package from a POM project (in Netbeans), all the jars have the version in the name and the EAR include the xxx-version.jar archives.

So, point two: the EAR problem.

In the EAR's pom.xml file, change the maven-ear-plugin adding in the configuration this property:

<fileNameMapping>no-version</fileNameMapping>

This is my plugin setting for example:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-ear-plugin</artifactId>
   <version>2.8</version>
   <configuration>
       <version>6</version>
       <defaultLibBundleDir>lib</defaultLibBundleDir>
       <fileNameMapping>no-version</fileNameMapping>
   </configuration>
</plugin>

So, now when i compile all the archives from a project pom, all the version numbers are removed from the jars.

Daniele Licitra
  • 1,520
  • 21
  • 45