简体   繁体   English

蚂蚁警告:“'includeantruntime'未设置”

[英]ant warning: “'includeantruntime' was not set”

I receive the following warning: 我收到以下警告:

[javac] build.xml:9: warning: 'includeantruntime' was not set, 
defaulting to build.sysclasspath=last; set to false for repeatable builds

What does this mean? 这是什么意思?

Ant Runtime 蚂蚁运行时

Simply set includeantruntime="false" : 只需设置includeantruntime="false"

<javac includeantruntime="false" ...>...</javac>

If you have to use the javac -task multiple times you might want to consider using PreSetDef to define your own javac -task that always sets includeantruntime="false" . 如果必须多次使用javac -task,则可能需要考虑使用PreSetDef来定义自己的javac -task,它始终设置includeantruntime="false"

Additional Details 额外细节

From http://www.coderanch.com/t/503097/tools/warning-includeantruntime-was-not-set : 来自http://www.coderanch.com/t/503097/tools/warning-includeantruntime-was-not-set

That's caused by a misfeature introduced in Ant 1.8. 这是由Ant 1.8中引入的错误引起的。 Just add an attribute of that name to the javac task, set it to false, and forget it ever happened. 只需将该名称的属性添加到javac任务,将其设置为false,并忘记它曾发生过。

From http://ant.apache.org/manual/Tasks/javac.html : 来自http://ant.apache.org/manual/Tasks/javac.html

Whether to include the Ant run-time libraries in the classpath; 是否在类路径中包含Ant运行时库; defaults to yes, unless build.sysclasspath is set. 默认为yes,除非设置了build.sysclasspath。 It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run. 通常最好将其设置为false,以便脚本的行为对运行它的环境不敏感。

As @Daniel Kutik mentioned, presetdef is a good option. 正如@Daniel Kutik所提到的, presetdef是一个不错的选择。 Especially if one is working on a project with many build.xml files which one cannot, or prefers not to, edit (eg, those from third-parties.) 特别是如果一个人正在处理一个包含许多build.xml文件的项目,这些文件不能或不愿编辑(例如,来自第三方的文件)。

To use presetdef , add these lines in your top-level build.xml file: 要使用presetdef ,请在顶级build.xml文件中添加以下行:

  <presetdef name="javac">
    <javac includeantruntime="false" />
  </presetdef>

Now all subsequent javac tasks will essentially inherit includeantruntime="false" . 现在所有后续的javac任务基本上都会继承includeantruntime="false" If your projects do actually need ant runtime libraries, you can either add them explicitly to your build files OR set includeantruntime="true" . 如果您的项目确实需要ant运行时库,您可以将它们显式添加到构建文件中,或者设置includeantruntime="true" The latter will also get rid of warnings. 后者也将摆脱警告。

Subsequent javac tasks can still explicitly change this if desired, for example: 如果需要,后续的javac任务仍然可以明确地更改它,例如:

<javac destdir="out" includeantruntime="true">
  <src path="foo.java" />
  <src path="bar.java" />
</javac>

I'd recommend against using ANT_OPTS . 我建议不要使用ANT_OPTS It works, but it defeats the purpose of the warning. 它有效,但它违背了警告的目的。 The warning tells one that one's build might behave differently on another system. 警告告诉一个人的构建可能在另一个系统上表现不同。 Using ANT_OPTS makes this even more likely because now every system needs to use ANT_OPTS in the same way. 使用ANT_OPTS使这更有可能,因为现在每个系统都需要以相同的方式使用ANT_OPTS Also, ANT_OPTS will apply globally, suppressing warnings willy-nilly in all your projects 此外, ANT_OPTS将在全球范围内应用,在您的所有项目中都会ANT_OPTS禁止警告

Chet Hosey wrote a nice explanation here : Chet Hosey 在这里写了一个很好的解释:

Historically, Ant always included its own runtime in the classpath made available to the javac task. 从历史上看,Ant总是将自己的运行时包含在可用于javac任务的类路径中。 So any libraries included with Ant, and any libraries available to ant, are automatically in your build's classpath whether you like it or not. 因此,Ant中包含的任何库以及ant可用的任何库都会自动出现在构建的类路径中,无论您是否喜欢它。

It was decided that this probably wasn't what most people wanted. 决定这可能不是大多数人想要的。 So now there's an option for it. 所以现在有一个选择。

If you choose "true" (for includeantruntime), then at least you know that your build classpath will include the Ant runtime. 如果选择“true”(对于includeantruntime),那么至少你知道你的构建类路径将包含Ant运行时。 If you choose "false" then you are accepting the fact that the build behavior will change between older versions and 1.8+. 如果选择“false”,那么您接受这样的事实:构建行为将在旧版本和1.8+之间发生变化。

As annoyed as you are to see this warning, you'd be even less happy if your builds broke entirely. 正如你要看到这个警告一样恼火,如果你的构建完全破坏,你会更不高兴。 Keeping this default behavior allows unmodified build files to work consistently between versions of Ant. 保持此默认行为允许未修改的构建文件在Ant版本之间保持一致。

The answer from Daniel works just perfect. 丹尼尔的答案非常完美。 Here is a sample snippet that I added to my build.xml: 这是我添加到build.xml的示例代码段:

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
                                                 <!--   ^^^^^^^^^^^^^^^^^^^^^^^^^  -->
        <classpath>
            <path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
            <path id="junit" location="${lib.dir}/junit-4.9b2.jar"/>
        </classpath>
    </javac>
</target>

Use <property name="build.sysclasspath" value="last"/> in your build.xml file 在build.xml文件中使用<property name="build.sysclasspath" value="last"/>

For more details search includeAntRuntime in Ant javac 有关详细信息,请在Ant javac中搜索includeAntRuntime

Other possible values could be found here 其他可能的值可以在这里找到

If you like me work from commandline the quick answer is executing 如果你喜欢我从命令行工作,快速答案正在执行

export ANT_OPTS=-Dbuild.sysclasspath=ignore

And then run your ant script again. 然后再次运行您的ant脚本。

i faced this same, i check in in program and feature. 我面对同样的问题,我会检查程序和功能。 there was an update has install for jdk1.8 which is not compatible with my old setting(jdk1.6.0) for ant in eclipse. 有一个更新已安装jdk1.8与eclipse中的ant的旧设置(jdk1.6.0)不兼容。 I install that update. 我安装了这个更新。 right now, my ant project is build success. 现在,我的蚂蚁项目取得了成功。

Try it, hope this will be helpful. 试试吧,希望这会有所帮助。

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

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