无法从代码中执行ANT

时间:2011-04-07 00:40:23

标签: java eclipse ant antrunner

我正在使用Eclipse Helios,我有ANT文件来完成一些任务(编译java代码)。 但是我无法使用代码执行ANT文件。这些是我的代码:

AntRunner runner = new AntRunner();
runner.setBuildFileLocation(fileDir);
runner.setArguments("-Dmessage=Building -verbose");

当我运行它时,我收到了这个错误:

java.lang.ClassNotFoundException: org.eclipse.ant.core.AntRunner
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at nz.ac.auckland.cs.marama.model.hotdeployment.HotDeployClassLoader.loadClassByParent(HotDeployClassLoader.java:83)
at nz.ac.auckland.cs.marama.model.hotdeployment.HotDeployClassLoader$RuntimeClassLoader.loadClass(HotDeployClassLoader.java:144)
at nz.ac.auckland.cs.marama.userdirectory.tools.MaramaEssential.handlers.visualhandlers.usertriggeringhandlers.ExecuteTestSuite.executeTestSuite(ExecuteTestSuite.java:57)
at nz.ac.auckland.cs.marama.userdirectory.tools.MaramaEssential.handlers.visualhandlers.usertriggeringhandlers.ExecuteTestSuite.notifyChanged(ExecuteTestSuite.java:41)
at nz.ac.auckland.cs.marama.editor.MaramaEditorContextMenuProvider$UserEventAction.run(MaramaEditorContextMenuProvider.java:197)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)

谁能告诉我这意味着什么?我可以使用Eclipse右键单击功能执行ANT,但我不能通过我的代码调用它。

由于

1 个答案:

答案 0 :(得分:2)

这意味着AntRunner不在您的类路径上。您正在使用的类是Eclipse的一部分。您需要找到Eclipse中的哪个JAR包含该类,并将其添加到类路径中。

或者,我建议您使用不同的方法来启动Ant构建。例如,快速谷歌搜索出现了this