简体   繁体   中英

Version number in .java and ant script

I'm developing java 1.4 (upgrade not possible) application using Eclipse. Application version number is placed in one of my classes public string and it must be logged at startup. Post build event runs ant script that zips compiled project and copies file to location on network available for others.

This works fine, but now I would like to make it better. I would like to place zip file in directory that contains version number. Where is best place to keep version number to make it available for ant and java app?

Place the version number in the Ant build.xml . This can be done in through the Ant jar task , as seen below:

<jar destfile="build/main/checksites.jar">
    <fileset dir="build/main/classes" />
    <manifest>
        <attribute name="Implementation-Title" value="The name of the project" />
        <attribute name="Implementation-Version" value="2.2.3" />
    </manifest>
</jar>

See Setting Package Version Information for the MANIFEST.MF key / value details.

Below an example where the project.version is given as a project property, which then is used in the Ant jar task:

<property name="project.version">2.2.3</property>

<jar destfile="build/main/checksites.jar">
    <fileset dir="build/main/classes" />
    <manifest>
        <attribute name="Implementation-Title" value="The name of the project" />
        <attribute name="Implementation-Version" value="${project.version}" />
    </manifest>
</jar>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM