我有一个项目想使用多种配置来构建。
我有一个常量需要在构建之间有所不同,但我不知道如何根据我的配置更改它。
例如,我希望能够根据配置文件中的值执行以下操作。
@WebService(targetNamespace = "http://example.com/")
public class CustomerWebService {
and
@WebService(targetNamespace = "http://demo.example.com/")
public class CustomerWebService {
我们使用 ant 来构建。
我建议尝试模拟 Maven 资源过滤和配置文件属性
源过滤
src/templates/MyFile.java
..
@WebService(targetNamespace = "@WS_NAMESPACE@")
public class CustomerWebService {
..
构建.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>
Notes:
建立档案
财产文件
每个配置都有不同的属性文件
src/properties/dev.properties
src/properties/qa.properties
src/properties/prod.properties
..
构建.xml
<property name="profile" value="dev"/>
<property file="src/properties/${profile}.properties"/>
选择替代构建配置文件
ant -Dprofile=qa ..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)