我想通过java代码执行ant构建。我使用以下代码,出现错误。
Ant helper = new Ant();
helper.setTarget("build_new");
helper.setAntfile("build_new.xml");
helper.execute();
错误:
线程"AWT-EventQueue-0"java.lang.NullPointerException中出现异常网址:org.apache.tools.ant.taskdefs.ant.init(ant.java:125)网址:org.apache.tools.ant.taskdefs.ant.reinit(ant.java:139)网址:org.apache.tools.ant.taskdefs.ant.execute(ant.java:292)网址:com.demo.test.JavaSamp$4.actionPerformed(JavaSamp.java:216)位于javax.swing.AbstractButton.fireActionPerformed(未知源)位于javax.swing.AbstractButton$Handler.actionPerformed(未知源)位于javax.swing.DefaultButtonModel.fireActionPerformed(未知源)位于javax.swing.DefaultButtonModel.setPressed(未知源)位于javax.swing.AbstractButton.doClick(未知源代码)位于javax.swing.plaf.basic.BasicMenuItemUI.doClick(未知源)位于javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(未知源)位于java.awt.Component.processMouseEvent(未知源)位于javax.swing.JComponent.processMouseEvent(未知源)位于java.awt.Component.processEvent(未知源)位于java.awt.Container.processEvent(未知源)位于java.awt.Component.dispatchEventImpl(未知源)位于java.awt.Container.dispatchEventImpl(未知源)位于java.awt.Component.dispatchEvent(未知源)位于java.awt.LightweightDispatcher.retargetMouseEvent(未知源)位于java.awt.LightweightDispatcher.processMouseEvent(未知源)位于java.awt.LightweightDispatcher.dispatchEvent(未知源)位于java.awt.Container.dispatchEventImpl(未知源)位于java.awt.Window.dispatchEventImpl(未知源)位于java.awt.Component.dispatchEvent(未知源)位于java.awt.EventQueue.dispatchEventImpl(未知源)位于java.awt.EventQueue.access$000(未知来源)位于java.awt.EventQueue$1.run(未知源)位于java.awt.EventQueue$1.run(未知源)位于java.security.AccessController.doPrivileged(本机方法)在java.security.AccessControlContext$1.doIntersectionPrivilege(未知源)在java.security.AccessControlContext$1.doIntersectionPrivilege(未知源)位于java.awt.EventQueue$2.run(未知源)位于java.awt.EventQueue$2.run(未知源)位于java.security.AccessController.doPrivileged(本机方法)在java.security.AccessControlContext$1.doIntersectionPrivilege(未知源)位于java.awt.EventQueue.dispatchEvent(未知源)位于java.awt.EventDispatchThread.pumpOneEventForFilters(未知源)位于java.awt.EventDispatchThread.pumpEventsForFilter(未知源)位于java.awt.EventDispatchThread.pumpEventsForHierarchy(未知源)位于java.awt.EventDispatchThread.pumpEvents(未知源)位于java.awt.EventDispatchThread.pumpEvents(未知源)位于java.awt.EventDispatchThread.run(未知源)
任何建议请
它也用于执行ant构建。
File buildFile = new File("build.xml");
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());