My problem is with running PigUnit via ant from a parent directory.
I am using the PigUnit example straight off of the PigUnit site.
The ant script I am using is here:
<junit printsummary="on" fork="true" haltonfailure="yes">
<jvmarg value="-Duser.dir=${basedir}"/>
<classpath refid="junit.class.path" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
This script works perfectly fine if I run ant in the working directory of the project. However, when I remotely call the script with this line of code in an ant build script in the Pig project’s parent directory
<ant dir="${pig.dir}" target="main" inheritall="false" antfile="build.xml"/>
I get a FileNotFoundException:
java.io.FileNotFoundException">java.io.FileNotFoundException: top_queries.pig (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.apache.pig.pigunit.PigTest.readFile(PigTest.java:273)
at org.apache.pig.pigunit.PigTest.readFile(PigTest.java:269)
at org.apache.pig.pigunit.PigTest.<init>(PigTest.java:92)
at TopQueriesTest.testTop2Queries(Unknown Source)
This same FNF exception also happens if I run ant from the command line in the parent directory:
ant -f PigJavaTest/build.xml junit
My workaround to helping PigUnit find top_queries.pig file to specifiy the top_queries.pig file’s location relative to the Pig project’s parent directory, e.g.
PigTest test = new PigTest("PigTestJava/top_queries.pig", args);
but this is not optimal because it breaks when running ant from a directory different from the parent one.
Other JUnit tests will run normally from the parent directory, but PigUnit always throws the same FNF exception. I also tried doing a simple test with PigServer (loading/dumping a file) and the PigServer test behaved just like PigUnit had.
Why does this FileNotFoundException get thrown when calling ant from the parent directory, and how can I fix it?
You have a relative path to your pig file. So if you call the ant script from the working directory of the project it should work. When you call the ant script from the parent project, the relative path now is relative to the parent directory.
when you call the ant task here, you are correctly setting the dir property, but that only changes the value of ${basedir} property for the follow in script, not the actual working directory when the junit task runs.
I suggest you use the dir attribute in your junit task to hard set the working directory (i guess that’s what you’re trying to do with the jvmarg option):
See http://ant.apache.org/manual/Tasks/junit.html for more details