1

我正在使用 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,但我不能通过我的代码调用它。

谢谢

4

1 回答 1

2

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

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

于 2011-04-07T00:47:03.457 回答