Now I go further...
but still got problem with the 'file path'
see here:
File file = new File("../config/log4j.properties"); //in this way, ant works, but use eclipse run ant doesn't work
File file = new File("./config/log4j.properties"); //in this way, ant doesn't work, but eclipse works
Anyone who know the solution, please help!!!
The error is caused by the path of build.xml. When I put it under <project_dir>/ant/ , Ant didn't work. So I put it under <project_dir>, then Ant works for me.
It caused by the relative path.
<project name="XXX" basedir="." default="run"> -- in build.xml
public static final String LOG4J_CONFIG_FILE_PATH = "./config/log4j.properties"; --in my Java class
build.xml should always put under project directory directly. In this way, it will avoid some unnecessary troubles.
Also http://ant.apache.org/manual/Tasks/java.html, it help me a lot!