我用POM文件的这一部分生成一个build-number:
<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:projectsmyProjecttargetmyProject-1.0.20130312133207.jar
Building jar: D:projectsmyProjecttargetmyProject-1.0.20130312133207-sources.jar
Building jar: D:projectsmyProjecttargetmyProject-1.0.20130312133207-javadoc.jar
Building zip: D:projectsmyProjecttargetmyProject-1.0.${project.build.number}.zip
为什么${项目。在zip-file中替换Number} ?是因为它是zip而不是jar吗?为什么版本会被替换?我怎么能告诉POM取代zip文件中的buildNumber ?
我已经尝试使用默认的$buildNumber而不是$project.build。数字,那也不行
编辑:我已经尝试了两个插件的不同阶段,但到目前为止还没有组合工作。
编辑2:如果你感兴趣的话,webstart - plugin部分是什么样子的,下面是代码:
<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插件样例应用程序
不要将buildNumberPropertyName参数设置为project.build.ANYTHING..以${project开头的表达式。XXX}解析基于MavenProject对象,所以你在${project.build。getBuild()返回的对象有getDate() getter,这是不正确的。
只是命名buildNumberPropertyName和timestampPropertyName参数不同,例如。myBuildNumber和myTimestamp,并相应地更改pom的其余部分