Java构建时间常量配置 [英] Java build time constant configuration
本文介绍了Java构建时间常量配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目要使用多种配置来构建.我有一个需要在不同版本之间有所不同的常量,但我不知道如何根据我的配置更改它.
I have a project I would like to build using multiple configurations. I have a constant that needs to be different between builds but I do not know how to change it based on my config.
例如,我希望能够根据配置文件中的值执行以下操作.
For example I would like to be able to do the following based off a value in a config file.
@WebService(targetNamespace = "http://example.com/")
public class CustomerWebService {
和
@WebService(targetNamespace = "http://demo.example.com/")
public class CustomerWebService {
我们使用蚂蚁来建造.
推荐答案
我建议尝试模拟 Maven 资源过滤和配置文件属性
I would advise attempting to emulate Maven resource filtering and profile properties
..
@WebService(targetNamespace = "@WS_NAMESPACE@")
public class CustomerWebService {
..
build.xml
<target name="filter-sources">
<copy todir="${build.dir}/src">
<fileset dir="src/templates" includes="**/*.java"/>
<filterset>
<filter token="WS_NAMESPACE" value="${ws.namespace}"/>
</filterset>
</copy>
</target>
<target name="compile" depends="filter-sources">
<javac destdir="${build.dir}/classes">
<src path="src/java"/>
<src path="${build.dir}/src"/>
<classpath>
..
..
</javac>
</target>
注意事项:
- ANT 复制任务能够执行模板替换.
每个配置都有不同的属性文件
Each configuration has a different property file
src/properties/dev.properties
src/properties/qa.properties
src/properties/prod.properties
..
build.xml
<property name="profile" value="dev"/>
<property file="src/properties/${profile}.properties"/>
选择替代构建配置文件
ant -Dprofile=qa ..
这篇关于Java构建时间常量配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文