Java build time constant configuration

后端 未结 1 1660
囚心锁ツ
囚心锁ツ 2021-01-15 03:22

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 o

相关标签:
1条回答
  • 2021-01-15 03:53

    I would advise attempting to emulate Maven resource filtering and profile properties

    Source filtering

    src/templates/MyFile.java

    ..
    @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>
    

    Notes:

    • The ANT copy task is capable of performing template substitutions.

    Build profiles

    Property files

    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"/>
    

    Choosing an alternative build profile

    ant -Dprofile=qa ..
    
    0 讨论(0)
提交回复
热议问题