vico
vico

Reputation: 18221

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?

Upvotes: 0

Views: 577

Answers (1)

Verhagen
Verhagen

Reputation: 4034

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>

Upvotes: 3

Related Questions