我使用 POM 文件的这一部分生成一个内部版本号:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<buildNumberPropertyName>project.build.number</buildNumberPropertyName>
<timestampPropertyName>project.build.time</timestampPropertyName>
<format>{0,date,yyyyMMddHHmmss}</format>
<items>
<item>timestamp</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
之后,我将 finalName 设置为:
<finalName>
${project.artifactId}-${project.version}.${project.build.number}
</finalName>
我还使用 webstart-maven-plugin 将项目生成为 webstart-app。webstart-plugin 生成一个 zip 文件。这一切都很好,除了一个小细节:
在构建时有以下输出:
[buildnumber:create]
Storing buildNumber: 20130312133207 at timestamp: 1363091527664
Building jar: D:\projects\myProject\target\myProject-1.0.20130312133207.jar
Building jar: D:\projects\myProject\target\myProject-1.0.20130312133207-sources.jar
Building jar: D:\projects\myProject\target\myProject-1.0.20130312133207-javadoc.jar
Building zip: D:\projects\myProject\target\myProject-1.0.${project.build.number}.zip
为什么 ${project.build.number} 没有在 zip 文件中替换?是因为它是zip而不是jar吗?那为什么要换版本呢?我如何告诉 POM 替换 zip 文件中的 buildNumber?
我已经尝试使用默认的 $buildNumber 而不是 $project.build.number,这也不起作用。
编辑:我已经为这两个插件尝试了不同的阶段,但到目前为止还没有组合。
Edit2:如果你感兴趣的话,Webstart-Plugin-part 的样子,这里是代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>jnlp</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- JNLP generation -->
<jnlp>
<!-- default values -->
<inputTemplateResourcePath>${project.basedir}</inputTemplateResourcePath>
<inputTemplate>src/main/jnlp/app.vm</inputTemplate> <!-- relative to inputTemplateResourcePath -->
<outputFile>app.jnlp</outputFile> <!-- defaults to launch.jnlp -->
<!-- used to automatically identify the jar containing the main class. -->
<!-- this is perhaps going to change -->
<mainClass>com.mycompany.myproject.App</mainClass>
</jnlp>
<sign>
<keystore>${basedir}/keystore</keystore>
<keypass>password</keypass> <!-- we need to override passwords easily from the command line. ${keypass} -->
<storepass>password</storepass> <!-- ${storepass} -->
<!--storetype>fillme</storetype-->
<alias>MyProjectWebstart</alias>
<!--validity>fillme</validity-->
<!-- only required for generating the keystore -->
<dnameCn>MyProjectWebstart</dnameCn>
<dnameOu>MyName</dnameOu>
<dnameO>MyCompany</dnameO>
<dnameL>MyTown</dnameL>
<dnameSt>MyState</dnameSt>
<dnameC>MyCountry</dnameC>
<verify>true</verify> <!-- verify that the signing operation succeeded -->
<!-- KEYSTORE MANAGEMENT -->
<keystoreConfig>
<delete>true</delete> <!-- delete the keystore -->
<gen>true</gen> <!-- optional shortcut to generate the store. -->
</keystoreConfig>
</sign>
</configuration>
</plugin>
我在那里使用了示例中的代码:寻找 Webstart Maven 插件示例应用程序