I have a third-party .jar
file in a res/lib
folder. The ANT build.xml
looks like this:
<?xml version="1.0"?>
<project name="my.project" basedir="." default="build">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build/classes"/>
<path id="master-classpath">
<fileset dir="res/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" optimize="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
</project>
The .java
file is the following:
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
public class IO {
public static void readCSVFile(File file) throws IOException {
FileReader in = new FileReader(file);
Iterable<CSVRecord> record = CSVFormat.DEFAULT.parse(in);
}
}
The compile is OK, but I got a runtime error: java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
. I think something is wrong with the classpath, but it seems ok to me.
UPDATE:
It is running if I use java -cp path;. Main
. I have tried to write an ANT script to run it:
<target name="run">
<java classname="Main">
<classpath refid="master-classpath"/>
</java>
</target>
I write ant run
in the command line, I get BUILD SUCCESSFUL
and nothing happens.