eclipse Ant 构建文件不包含 javac 任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10781503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:16:09  来源:igfitidea点击:

Ant buildfile does not contain a javac task

eclipsejakarta-ee

提问by Heniek

I have build.xml file and I want to create Java project from Existing Ant Buildfile. But I have an error: Specified buildfile does not contain a javac taskMy file has simple structure:

我有 build.xml 文件,我想从现有的 Ant Buildfile 创建 Java 项目。但是我有一个错误:指定的构建文件不包含 javac 任务我的文件结构简单:

<project>
     <target ...>
     </target>
     ...
</project>

回答by Puneet Pandey

Provide javac to your build.xml as below:

为您的 build.xml 提供 javac,如下所示:

<javac srcdir="src" destdir="bin" />

回答by Mike S

As Puneet Pandey pointed out, this error occurs when your build.xmlfile is lacking a <javac>XML element.

正如 Puneet Pandey 指出的那样,当您的build.xml文件缺少<javac>XML 元素时会发生此错误。

The <javac>XML element in the build.xmlfile (referred to as javac task) tells the compiler or IDE (Eclipse in this case) where the source Java files are for compiling. Once you know that it should be quite clear why Eclipse can't import your build.xmlwithout a <javac>XML element.

文件中的<javac>XML 元素build.xml(称为javac task)告诉编译器或 IDE(在本例中为 Eclipse)源 Java 文件用于编译的位置。一旦您知道为什么 Eclipse 不能在build.xml没有<javac>XML 元素的情况下导入您的内容就应该很清楚了。

In case you are not sure where to stick the <javac>tag I'll add a slightly fuller example. You will need to navigate to your build.xmland edit it so that it contains the <javac>line in the appropriate section insidethe <project>tag.

如果您不确定在哪里贴<javac>标签,我将添加一个稍微完整的示例。您需要导航至您build.xml和编辑它,以便它包含<javac>在相应的剖面线<project>标签。

<project ...>
  <javac srcdir="src" destdir="bin" />
  <target ...>
  </target>
  ...
</project>

回答by Asanka Umesh

You need something like this,

你需要这样的东西,

    <target name="compile">
  <javac destdir="build/classes" srcdir="src" includeantruntime="false">
    <classpath refid="compile.classpath"/>
  </javac>
  </target>

    <target name="war" depends="compile">   
  <war destfile="build/${name}.war" webxml="WebContent/WEB-INF/web.xml">
   <fileset dir="WebContent" casesensitive="no">
   </fileset>
   <lib dir="WebContent/WEB-INF/lib"/>
   <classes dir="build/classes">
   </classes>   
  </war>
</target>