如何构建没有版本的 maven 项目?

我有一个 maven 项目,我想建立没有版本。

现在,当我使用 maven 构建项目时,它会创建这个 commonjerseylib-1.0.war,但是我需要创建这个 commonjerseylib.war

除此之外,我从 pom.xml中删除了 <version>标记,但 Maven 仍然使用 war创建,默认版本为1.0。

我的 pom.xml:

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

没有版本如何构建它?

77875 次浏览

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.

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>

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

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