当使用ANT,我怎么能定义任务只有当我有一些特定的Java版本? [英] When using ANT, how can I define a task only if I have some specific java version?

查看:103
本文介绍了当使用ANT,我怎么能定义任务只有当我有一些特定的Java版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有蚂蚁在一个特定的步骤才能执行的问题,当我们的Java 1.5安装在生成计算机。定义使用该任务将使用使用1.5编译一个jar文件,所以用1.4虚拟机中运行会抛出异常IncompatibleClassVersion

I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.

我要同时找到解决这个任务,需要1.4这一具体项目的工作,但一个问题来找我。我怎样才能避免定义这个任务,并执行该可选步骤,如果我没有特定的Java版本?

I have to find a solution meanwhile to have this task working for this specific project that requires 1.4, but a question came to me. How can I avoid defining this task and executing this optional step if I don't have a specific java version?

我可以使用目标标记如果或,除非的标签,但这些只检查是否有属性设置与否。我也想有,不需要额外的库解决方案,但我不知道是否在标准的内置的功能足以执行这样的任务。

I could use the "if" or "unless" tags on the target tag, but those only check if a property is set or not. I also would like to have a solution that doesn't require extra libraries, but I don't know if the build-in functionality in standard is enough to perform such a task.

推荐答案

Java版本是通过的 ant.java.version 的属性公开。使用的条件的设置属性和执行任务,只有当它是真实的。

The Java version is exposed via the ant.java.version property. Use a condition to set a property and execute the task only if it is true.

<?xml version="1.0" encoding="UTF-8"?>

<project name="project" default="default">

    <target name="default" depends="javaCheck" if="isJava6">
        <echo message="Hello, World!" />
    </target>

    <target name="javaCheck">
        <echo message="ant.java.version=${ant.java.version}" />
        <condition property="isJava6">
        	<equals arg1="${ant.java.version}" arg2="1.6" />
        </condition>
    </target>

</project>

这篇关于当使用ANT,我怎么能定义任务只有当我有一些特定的Java版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆