Question

So i am having trouble running my project via the ant build.xml file. The project runs

perfectly when executed normally, image link posted below:

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

However, when the project is ran through a build.xml file, it produces this error below:

[code]

  <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>

[/code]

Error:

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

I am refraining from posting my assignment code due to others from school probably looking at this site for help as well

Any help would be appreciated :D

Was it helpful?

Solution

Your ant script compiles the java classes and puts them into the build directory (that's how it should be). This happens in the target named compile. I assume you have put your input file into the src folder in Eclipse. Eclipse also has a build directory - usually bin - and copies such files over automtically. (There are filters in the settings which define the file types it won't copy.)

The ant script does not copy the input file. So it cannot be found, when run from the ant script, but it is found when run from Eclipse.

To copy the input file, add this to the compile target:

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

This copies all .txt files from the src directory to the build directory.

(Note: As mentioned, I assume your text file is in the source directory. If it is not, this is probably not the correct solution.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top