简单的Java Ant构建问题

1 java xml ant build

完全是Ant新手,我只有一个简单的问题.我正在使用输入文件运行ant:ant -Dargs="input.txt" run但是它说它找不到input.txt(没有这样的文件或目录).我有build.xml文件,input.txt在同一目录中,上面srcbin.这是我的build.xml档案,我错过了什么吗?

<project name="Project" default="compile" basedir=".">

  <description>
    A build file for a project
  </description>

  <!-- global properties for this build file -->
  <property name="source.dir" location="src"/>
  <property name="build.dir" location="bin"/>
  <property name="doc.dir" location="doc"/>
  <property name="main.class" value="proj.ProjMain"/>

  <!-- set up some directories used by this project -->
  <target name="init" description="setup project directories">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${doc.dir}"/>
  </target>

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

  <!-- execute the program with the fully qualified name in ${build.dir} -->
  <target name="run" description="run the project">
    <java dir="${build.dir}" classname="${main.class}" fork="yes">
        <arg line="${args}"/>
    </java>
  </target>

  <!-- Delete the build & doc directories and Emacs backup (*~) files -->
  <target name="clean" description="tidy up the workspace">
    <delete dir="${build.dir}"/>
    <delete dir="${doc.dir}"/>
    <delete>
      <fileset defaultexcludes="no" dir="${source.dir}" includes="**/*~"/>
    </delete>
  </target>

  <!-- Generate javadocs for current project into ${doc.dir} -->
  <target name="doc" depends="init" description="generate documentation">
    <javadoc sourcepath="${source.dir}" destdir="${doc.dir}"/>
  </target>

</project>
Run Code Online (Sandbox Code Playgroud)

Pas*_*ent 6

该命令ant -Dargs="input.txt" run将运行以下目标:

  <!-- execute the program with the fully qualified name in ${build.dir} -->
  <target name="run" description="run the project">
    <java dir="${build.dir}" classname="${main.class}" fork="yes">
        <arg line="${args}"/>
    </java>
  </target>
Run Code Online (Sandbox Code Playgroud)

作为写在注释中,该目标执行Java程序${build.dir}目录(在这里bin),通过命令行参数给它.所以,如果input.txt在上面bin,你应该运行:

$ ant -Dargs="../input.txt" run
Run Code Online (Sandbox Code Playgroud)