我试图在Eclipse中使用Ant构建项目。我右键单击build.xml>运行方式> Ant Build。但是,我收到以下错误:
BUILD FAILED C:\Users\David\eclipse\test-project\build.xml:26: Class not found: javac1.8
还有一个警告:
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
正如我在其他文章中所读到的那样,这可能是由于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
编辑:这是整个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>
与您的Eclipse版本捆绑在一起的Ant版本与Java 1.8不兼容。
转到Ant下载页面,然后将最新版本提取到文件系统上适当的位置。
在Eclipse中,转到Window > Preferences > Ant > Runtime,单击Ant Home...按钮,然后选择将新下载的Ant提取到的位置。
Window > Preferences > Ant > Runtime
Ant Home...