Ant:找不到类:javac1.8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23442621/
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-08-13 23:00:58  来源:igfitidea点击:

Ant: Class not found: javac1.8

javaeclipseant

提问by David_Z

I am trying to build a project using Ant in eclipse. I right-clicked on build.xml > Run As > Ant Build. However, I am getting the following error:

我正在尝试在 Eclipse 中使用 Ant 构建一个项目。我右键单击 build.xml > Run As > Ant Build。但是,我收到以下错误:

BUILD FAILED
C:\Users\David\eclipse\test-project\build.xml:26: Class not found: javac1.8

and also a warning:

还有一个警告:

compile:
[javac] C:\Users\David\eclipse\test-project\build.xml:26: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

As I read in other posts that this might be due to having an ant version that is too old or not having set the environment variables correctly here is all the info:

正如我在其他帖子中读到的,这可能是由于 ant 版本太旧或没有正确设置环境变量,这里是所有信息:

C:\>java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

C:\>ant -version
Apache Ant(TM) version 1.9.3 compiled on December 23 2013

C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_05

C:\>echo %JRE_HOME%
C:\Program Files\Java\jre8

EDIT: Here is the whole build.xml, line 26 is the javac tag:

编辑:这是整个 build.xml,第 26 行是 javac 标记:

<?xml version="1.0"?>
<project name="test-project" default="main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="src.dir" location="src" />
  <property name="build.dir" location="bin" />
  <property name="dist.dir" location="dist" />
  <property name="docs.dir" location="docs" />

  <!-- Deletes the existing build, docs and dist directory-->
  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="${docs.dir}" />
    <delete dir="${dist.dir}" />
  </target>

  <!-- Creates the  build, docs and dist directory-->
  <target name="makedir">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${docs.dir}" />
    <mkdir dir="${dist.dir}" />
  </target>

  <!-- Compiles the java code (including the usage of library for JUnit -->
  <target name="compile" depends="clean, makedir">
    <javac srcdir="${src.dir}" destdir="${build.dir}">
    </javac>
  </target>

  <!-- Creates Javadoc -->
  <target name="docs" depends="compile">
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
      <!-- Define which files / directory should get included, we include all -->
       <fileset dir="${src.dir}">
                <include name="**" />
           </fileset>
    </javadoc>
  </target>

  <!--Creates the deployable jar file  -->
  <target name="jar" depends="compile">
    <jar destfile="${dist.dir}\test-project1.jar" basedir="${build.dir}">
      <manifest>
        <attribute name="Main-Class" value="test.Main" />
      </manifest>
    </jar>
  </target>

  <target name="main" depends="compile, jar, docs">
    <description>Main target</description>
  </target>

</project> 

采纳答案by Reinstate Monica 2331977

The version of Ant bundled with your version of Eclipse is not compatible with Java 1.8.

与您的 Eclipse 版本捆绑在一起的 Ant 版本与 Java 1.8 不兼容。

Go to the Ant download page, and extract the latest version somewhere appropriate onto your filesystem.

转至Ant 下载页面,将最新版本解压缩到文件系统的适当位置。

In Eclipse, go to Window > Preferences > Ant > Runtime, click the Ant Home...button, and select the location that you extracted the newly downloaded Ant to.

在 Eclipse 中,转到Window > Preferences > Ant > Runtime,单击Ant Home...按钮,然后选择您将新下载的 Ant 解压缩到的位置。

回答by kasi

Make sure your source files are in "ProjectDirectory/src".

确保您的源文件在“ProjectDirectory/src”中。

回答by David_Z

I already did some extensive googling before asking this question but continuing that I found a solution here: This issue seems to only appear when using JDK 1.8 so using JDK 1.7 instead solves the problem. The following line needs to be added to eclipse.ini:

在问这个问题之前,我已经做了一些广泛的谷歌搜索,但继续我在这里找到了一个解决方案:这个问题似乎只在使用 JDK 1.8 时出现,所以使用 JDK 1.7 来解决这个问题。需要在 eclipse.ini 中添加以下行:

-vm "path-to-jdk-1.7\bin\javaw.exe"

回答by smillien62

Mr. studro is right. I just confirmed an example on Ubuntu 14.04

斯特罗先生是对的。我刚刚在 Ubuntu 14.04 上确认了一个例子

sudo apt-get install ant
ant -version
Apache Ant (TM) Version 1.9.3 compiled on April August 2014

works perfectly in eclipse, just follow the steps described by Mr studro to configure the 'Ant Home' in eclipse with "/usr/share/ant".
Regards, Stéphane.

在eclipse中完美运行,只需按照sttro先生描述的步骤在eclipse中使用“/usr/share/ant”配置“Ant Home”。
问候,斯蒂芬。

回答by user1774051

I think, what you are seeing is Ant Bug 53347 (see https://issues.apache.org/bugzilla/show_bug.cgi?id=53347).

我想,你看到的是 Ant Bug 53347(参见https://issues.apache.org/bugzilla/show_bug.cgi?id=53347)。

If so, try either pf the following workarounds:

如果是这样,请尝试以下解决方法:

Set the property "build.compiler" to a meaningful value like "javac1.7", or "javac1.3".

将属性“build.compiler”设置为有意义的值,例如“javac1.7”或“javac1.3”。

Set the "compiler" attribute of the "javac" element of your build script to either of the above values. For all possible values, and their meaning, see http://ant.apache.org/manual/Tasks/javac.html

将构建脚本的“javac”元素的“compiler”属性设置为上述值之一。有关所有可能的值及其含义,请参阅http://ant.apache.org/manual/Tasks/javac.html

回答by vimal krishna

To make it still more clear.

为了让它更清楚。

1>Set JAVA_HOME,JRE_HOME and Update Ant to 1.9

1>设置JAVA_HOME、JRE_HOME并将Ant更新为1.9

2>Over build.xml right click => run as (this takes into configuration)==>Now in this Edit Configuration and launch pop-up window

2> 在 build.xml 上右键单击 => 运行方式(这将进入配置)==> 现在在此编辑配置中并启动弹出窗口

select Main tab then the third form field called "Arguments" add:

选择 Main 选项卡,然后添加名为“Arguments”的第三个表单字段:

-Dbuild.compiler=javac1.7

3> In build.xml add includeantruntime="false"

3> 在 build.xml 添加 includeantruntime="false"

<javac srcdir="${src}" destdir="${bin}" debug="true" encoding="ISO-8859-1" includeantruntime="false">
        <classpath refid="my.classpath"/>
</javac>

Edit configuration

编辑配置

It should compile without any message

它应该在没有任何消息的情况下编译