java - 如何从使用 Eclipse 进行构建过渡到使用 Ant

标签 java eclipse ant eclipse-3.6

我在 Eclipse Helios 中有一个 Spring Web 应用程序。我在其他项目上使用 Ant 进行构建,但不熟悉最初设置 Ant 构建文件。是否有一种轻松的方法可以从使用 Eclipse 进行构建过渡到创建 Ant 构建文件和任何支持文件?我尝试将基本的 Ant 构建文件复制到我的应用程序中,但我不确定它是否接近我的需要。我已将其包含在下面。当我运行它时,它给了我这个错误。

BUILD FAILED
C:\..\..\workspace\..\build.xml:21: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.

我的系统JAVA_HOME路径设置为'C:\Program Files\Java\jdk1.7.0\bin'

<?xml version="1.0" encoding="UTF-8"?>
<project name="projectName" default="dist" basedir=".">
<description>
    build file
  </description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist"  location="dist"/>

<target name="init">
  <!-- Create the time stamp -->
  <tstamp/>
  <!-- Create the build directory structure used by compile -->
  <mkdir dir="${build}"/>
</target>

<target name="compile" depends="init"
    description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>

<target name="dist" depends="compile"
    description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>

<!-- Put everything in ${build} into the News-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/ProjectName-${DSTAMP}.jar" basedir="${build}"/>
</target>

<target name="clean"
    description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

最佳答案

请勿在 JAVA_HOME 中包含 bin 文件夹

试试这个:

C:\Program Files\Java\jdk1.7.0

关于java - 如何从使用 Eclipse 进行构建过渡到使用 Ant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7073077/

相关文章:

java - 使用 <context :property-placeholder> in a factory method 定义的属性

java - 我可以让 ant 输出等效的脚本吗?

java - BIRT NoClassDefFoundError

Java双参数递归

android - XML Relative Layout order change Crashes 程序 (Android)

java - Eclipse 解析器不应该检测到这种 IndexOutOfBounds 异常吗?

android - 即使模拟器正在运行也找不到设备

java - 用于跨多个 war 文件共享 session 数据的 Tomcat ServletContext 与 JNDI

java - ChoiceBox 未在 JavaFX 中设置 ObservableList

c++ - Visual Studio C++ - 像在 Eclipse 中一样在鼠标悬停时显示函数代码