java - Ant命令运行问题

标签 java ant build.xml

所以我无法通过 ant build.xml 文件运行我的项目。项目运行

正常执行时完美,图片链接如下:

http://puu.sh/75krJ.png

但是,当项目通过 build.xml 文件运行时,会产生以下错误:

[代码]

  <description>
    Ant Build File for myproj0/
  </description>

  <!-- Property Names -->
  <property name="src" location="src" />
  <property name="build" location="build" />
  <property name="main.class" value="driver.Driver"/>
  <property name="doc" location="doc" />

  <!-- initializes the program -->
  <target name="init">
    <mkdir dir="${build}"/>
    <mkdir dir="${src}"/> 
  </target>

  <target name="compile" depends="init" description="Compiles source code">
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="run" description="Runs the main">
    <java dir="${build}" classname="${main.class}" fork="yes" >
      <classpath>
    <pathelement location="${build}" />
      </classpath>
     </java>
  </target>

  <target name="clean" description="Deletes the created directories">
    <delete dir="${build}"/>
    <delete dir="bin"/>
    <delete dir="doc"/>
  </target>

  <target name="doc" description="Generates the Javadoc" depends="compile">
    <javadoc sourcepath="${src}" destdir="${doc}" />
  </target>

</project>

[/代码]

错误:

http://puu.sh/75kRy.png

我没有发布我的作业代码,因为学校里的其他人可能也在看这个网站寻求帮助

任何帮助将不胜感激:D

最佳答案

您的 ant 脚本编译 java 类并将它们放入 build 目录(应该是这样)。这发生在名为 compile 的目标中。我假设您已将输入文件放入 Eclipse 中的 src 文件夹中。 Eclipse 也有一个构建目录——通常是 bin——并自动复制这些文件。 (设置中的过滤器定义了它不会复制的文件类型。)

ant 脚本不复制输入文件。所以当从 ant 脚本运行时找不到它,但是当从 Eclipse 运行时找到它。

要复制输入文件,将其添加到编译目标:

  <copy todir="${build}">
     <fileset dir="${src}" includes="*.txt" />
  </copy>

这会将所有 .txt 文件从 src 目录复制到构建目录。

(注意:如前所述,我假设您的文本文件位于源目录中。如果不是,这可能不是正确的解决方案。)

关于java - Ant命令运行问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21948655/

相关文章:

java.lang.VerifyError : Expecting a stackmap frame at branch target 错误

android - build.xml 在编译包含 ArduinoAdkUsb 的 Processing sketch 时出错

java - ant: "depends"目标的执行顺序?

java - ConcurrentModificationException 在 android 中为每个抛出

java - srcs 和非 srcs jar 之间的区别?

通过 Ant 任务使用来自 J2SE 类的 {@inheritDoc} 的 Javadoc

java - 开始看到对象堆异常 Java 6

java - 使用文件集和路径元素在 build.xml 中设置类路径的区别

java - "method is ambiguous for the type"但类型不明确(错误来自从 eclipse 3.7.2 升级到 eclipse 4.2)

java - 为什么 Java Collections API 不包含图形实现?