How to build maven project without version?

Maven

Maven Problem Overview


I have a maven project that I want to build without version.

Now, when I build the project using maven, it creates this commonjerseylib-1.0.war but I need this commonjerseylib.war to be created.

In addition to that, I remove <version> tag from pom.xml but still Maven is creating with war with version 1.0 by default.

My pom.xml :

      <modelVersion>4.0.0</modelVersion>
      <groupId>commonjerseylib</groupId>
      <artifactId>commonjerseylib</artifactId>
      <packaging>ear</packaging>
      <name>commonjerseylib</name>
      <!--<version>1.0</version>-->

How to build it without version ?

Maven Solutions


Solution 1 - Maven

You will always need a version number for a project, however it is possible to change the name of the generated package (JAR, WAR, EAR, etc.) through the <finalName> element in the POM.

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

or in older versions of maven:

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

By default, the finalName is ${project.artifactId}-${project.version}, but this can be changed to something else. This will only affect the name of the package created in the target directory; the file name in the local repository and uploaded to remote repositories will always have a version number.

See the POM reference documentation for more information.

Solution 2 - Maven

in maven war plugin in build, change

<warName> ${artifactId} </warName>

        <build>
           ..........
             <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<!-- web.xml is not mandatory since JavaEE 5 -->
					<failOnMissingWebXml>false</failOnMissingWebXml>
					<warName>${artifactId}</warName>
				</configuration>
			</plugin>
         .............
       <build>

Solution 3 - Maven

I fixed it with the below lines of code in the pom

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1137387View Question on Stackoverflow
Solution 1 - MavenprungeView Answer on Stackoverflow
Solution 2 - MavenkuhajeyanView Answer on Stackoverflow
Solution 3 - MavenShahid Hussain AbbasiView Answer on Stackoverflow