如何将maven项目版本放入war文件清单中?

时间:2022-07-11 23:56:49

I need to have Maven insert the version number from the POM file into the manifest located in the WAR file under /WEB-INF/manifest.mf.

我需要让Maven将POM文件中的版本号插入位于/WEB-INF/manifest.mf下的WAR文件中的清单中。

How do I do this? I was able to easily file documentation for doing this in a JAR file using the maven-jar-plugin, but that does not work on a WAR file.

我该怎么做呢?我能够使用maven-jar-plugin轻松地在JAR文件中提交文档以进行此操作,但这不适用于WAR文件。

Thanks for the help!

谢谢您的帮助!

3 个解决方案

#1


32  

Figured it out using the maven-war-plugin. See the configuration below:

使用maven-war-plugin计算出来。请参阅以下配置:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>2.1.1</version>
     <configuration>
         <archive>
             <manifestEntries>
                 <version>${project.version}</version>
             </manifestEntries>
         </archive>
     </configuration>
</plugin>

#2


18  

Or you can use the addDefaultImplementationEntries or addDefaultSpecificationEntries flags which will add several entries including the project.version property.

或者您可以使用addDefaultImplementationEntries或addDefaultSpecificationEntries标志,这些标志将添加几个条目,包括project.version属性。

addDefaultImplementationEntries

addDefaultImplementationEntries

Implementation-Title: ${project.name}
Implementation-Version: ${project.version}
Implementation-Vendor-Id: ${project.groupId}
Implementation-Vendor: ${project.organization.name}
Implementation-URL: ${project.url}

addDefaultSpecificationEntries

addDefaultSpecificationEntries

Specification-Title: ${project.name}
Specification-Version: ${project.version}
Specification-Vendor: ${project.organization.name}

Default value for both is false. If a property is not defined (e.g. project.organization.name), then that line will be excluded from the manifest.

两者的默认值均为false。如果未定义属性(例如project.organization.name),则该行将从清单中排除。

This could go into the maven-war-plugin configuration as follows:

这可以进入maven-war-plugin配置,如下所示:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
        </archive>
    </configuration>
</plugin>

#3


-1  

Put ${project.version} in your manifest.mf where you want the version to be. In order for this to work, I believe you need the resources plugin so that manven will 'filter' resources as they are included in your war file.

将$ {project.version}放在您希望版本所在的manifest.mf中。为了实现这一点,我相信您需要资源插件,以便manven将“过滤”资源,因为它们包含在您的war文件中。

#1


32  

Figured it out using the maven-war-plugin. See the configuration below:

使用maven-war-plugin计算出来。请参阅以下配置:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>2.1.1</version>
     <configuration>
         <archive>
             <manifestEntries>
                 <version>${project.version}</version>
             </manifestEntries>
         </archive>
     </configuration>
</plugin>

#2


18  

Or you can use the addDefaultImplementationEntries or addDefaultSpecificationEntries flags which will add several entries including the project.version property.

或者您可以使用addDefaultImplementationEntries或addDefaultSpecificationEntries标志,这些标志将添加几个条目,包括project.version属性。

addDefaultImplementationEntries

addDefaultImplementationEntries

Implementation-Title: ${project.name}
Implementation-Version: ${project.version}
Implementation-Vendor-Id: ${project.groupId}
Implementation-Vendor: ${project.organization.name}
Implementation-URL: ${project.url}

addDefaultSpecificationEntries

addDefaultSpecificationEntries

Specification-Title: ${project.name}
Specification-Version: ${project.version}
Specification-Vendor: ${project.organization.name}

Default value for both is false. If a property is not defined (e.g. project.organization.name), then that line will be excluded from the manifest.

两者的默认值均为false。如果未定义属性(例如project.organization.name),则该行将从清单中排除。

This could go into the maven-war-plugin configuration as follows:

这可以进入maven-war-plugin配置,如下所示:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <archive>
            <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
        </archive>
    </configuration>
</plugin>

#3


-1  

Put ${project.version} in your manifest.mf where you want the version to be. In order for this to work, I believe you need the resources plugin so that manven will 'filter' resources as they are included in your war file.

将$ {project.version}放在您希望版本所在的manifest.mf中。为了实现这一点,我相信您需要资源插件,以便manven将“过滤”资源,因为它们包含在您的war文件中。