我不确定这是否是一个理想的解决方案,但我做了以下操作:
要正确设置应用程序标题,必须设置产品名称,因为它也用于About <productName>-menu 项,而且在调用Platform.getProduct().getName() 时会返回它。 (有时在我的旧产品中使用。)
要在构建时设置产品名称,我执行以下操作:
- 从
plugin.properties 文件中读取产品名称
- 使用 Tycho (Maven) 修改
plugin.properties
1.从plugin.properties 文件中读取产品名称
为了更容易通过 Maven 修改产品名称,该字符串被外部化为 plugin.properties。
在插件配置文件和plugin.xml中,产品名称应设置为%product.name。
然后在plugin.properties 中添加以下行:
product.name=@productName@
如果你现在开始你的产品,应用标题应该是@productName@。
2。使用 Tycho (Maven) 修改 plugin.properties
要将 @productName@ 更改为所需的文本,请使用 Maven filtering。如果使用标准过滤分隔符 (${productName}),Eclipse 将无法启动该产品,因此我使用 Ant 之类的分隔符。这个sn-p需要添加到pom中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
<delimiters>
<delimiter>${*}</delimiter><!-- to keep the default behavior -->
<delimiter>@</delimiter><!-- to add Ant-like tokens style, this is needed as RCP has problems with the accolades -->
</delimiters>
</configuration>
</plugin>
我找到了这个解决方案here on SO。
要将 @productName@ 替换为实际值,必须在 pom 中定义 Maven 属性 <productName>:
<properties>
<productName>MyApp_${maven.build.timestamp}</productName>
</properties>
<productName> 可以包含任何值,例如${buildNumber} 来自Build Number Maven Plugin。
现在唯一缺少的部分是以下激活过滤的sn-p:
<resources>
<resource>
<directory>./</directory>
<includes>
<include>plugin.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>