我有一個build.xml來爲我的應用程序生成Jar文件。ANT:如何從Java調用ANT build.xml文件
我想直接調用build.xml文件如下圖所示
import java.io.IOException;
public class RunBuild {
public static void main(String args[]) throws IOException {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("/home/sai/Jan5WS/AntTest/build.xml");
}
}
它不扔任何異常,但它不是生成jar文件。
我使用Ubuntu 12個螞蟻8.1 verions目前
有誰請告訴我可能是錯的?
感謝
編輯部分
我試圖運行它這樣
公共靜態無效的主要(字符串ARGS [])拋出IOException異常{
File buildFile = new File("build.xml", "/home/sai/Jan5WS/AntTest");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
Bu t投擲
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/AntMain
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.tools.ant.Project.initProperties(Project.java:313)
at org.apache.tools.ant.Project.init(Project.java:300)
at RunBuild.main(RunBuild.java:15)
您是如何運行代碼的?你的班級路徑可能沒有全部庫。日誌中是否存在ClassNotFoundException? – Jayan