gpt4 book ai didi

ant - 在我的插件中调用 ant 任务并将输出重定向到控制台

转载 作者:行者123 更新时间:2023-12-02 00:24:14 26 4
gpt4 key购买 nike

在我的 eclipse 插件中,我试图执行 Ant 任务并将输出重定向到 eclipse 控制台这是我的代码:

    AntRunner runner = new AntRunner();
runner.addBuildLogger("myplugin.AntLogger");

String projectPath = getProject().getLocation().toString();
String buildFileLocation = projectPath + File.separator + "build.xml";
runner.setBuildFileLocation(buildFileLocation);
runner.setExecutionTargets(new String[] { "build-for-device" });

AntLogger 代码为:

public class AntLogger extends org.apache.tools.ant.DefaultLogger {

private IOConsole console = new IOConsole("Ant", null);
private IOConsoleOutputStream outputStream = console.newOutputStream();

public AntLogger() {
ConsolePlugin.getDefault().getConsoleManager()
.addConsoles(new IConsole[] { console });
}

@Override
protected void printMessage(String message, PrintStream stream, int priority) {
super.printMessage(message, stream, priority);
try {
outputStream.write(message + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}

然后我将 ant.jar 添加到 plugin.xml

<extension
point="org.eclipse.ant.core.extraClasspathEntries">
<extraClasspathEntry
library="ant.jar">
</extraClasspathEntry>
</extension>

无论我做什么,我都会收到未找到类的异常:

java.lang.NoClassDefFoundError: org/apache/tools/ant/DefaultLogger
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:626)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:608)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:562)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:486)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:459)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:476)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
at org.eclipse.ant.core.AntCorePreferences$WrappedClassLoader.findClass(AntCorePreferences.java:116)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.ant.internal.core.AntClassLoader.loadClassPlugins(AntClassLoader.java:69)
at org.eclipse.ant.internal.core.AntClassLoader.findClass(AntClassLoader.java:47)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.createLogger(InternalAntRunner.java:747)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.addBuildListeners(InternalAntRunner.java:202)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:572)
at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:498)
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.ant.core.AntRunner.run(AntRunner.java:378)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:475)

最佳答案

经过一番苦思冥想,我终于找到了解决方案:

AntLogger 类不能是插件项目的一部分。我将 AntLogger 移动到另一个名为 EclipseAntLogger 的 java 项目,然后我将项目 jar 添加到插件扩展点,如下所示:

<extension
point="org.eclipse.ant.core.extraClasspathEntries">
<extraClasspathEntry
library="lib/EclipseAntLogger.jar">
</extraClasspathEntry>
</extension>

关于ant - 在我的插件中调用 ant 任务并将输出重定向到控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9501936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com