简体   繁体   English

.java和ant脚本中的版本号

[英]Version number in .java and ant script

I'm developing java 1.4 (upgrade not possible) application using Eclipse. 我正在使用Eclipse开发Java 1.4(无法升级)应用程序。 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. 生成后事件运行ant脚本,该脚本压缩已编译的项目并将文件复制到网络上可供其他人使用的位置。

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. 我想将zip文件放在包含版本号的目录中。 Where is best place to keep version number to make it available for ant and java app? 在哪里最好保留版本号以使其可用于ant和java应用程序?

Place the version number in the Ant build.xml . 将版本号放在Ant build.xml This can be done in through the Ant jar task , as seen below: 这可以通过Ant jar任务完成 ,如下所示:

<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. 有关MANIFEST.MF键/值的详细信息 ,请参阅设置程序包版本信息

Below an example where the project.version is given as a project property, which then is used in the Ant jar task: 在下面的示例中,将project.version作为项目属性给出,然后在Ant jar任务中使用该属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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