gpt4 book ai didi

java - 通过eclipse插件执行ant Target

转载 作者:行者123 更新时间:2023-11-29 09:08:53 25 4
gpt4 key购买 nike

package testrunner.popup.actions;

import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.types.Path;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

public class AntExecuter {

public boolean executeAntTask(String buildXmlFileFullPath,String className,String methodName,String mode) {

System.getProperty("ANT_HOME");

boolean success = false;

MessageConsole myConsole = findConsole("Scenario Test");
MessageConsoleStream out = myConsole.newMessageStream();

MyLogger myLogger = new MyLogger();
myLogger.setErrorPrintStream(System.err);
myLogger.setOutputPrintStream(System.out);
myLogger.setMessageOutputLevel(Project.MSG_INFO);

Project project = new Project();
File buildFile = new File(buildXmlFileFullPath);



project.setUserProperty("ant.file", buildFile.getAbsolutePath());
project.addBuildListener(myLogger);


try {
project.fireBuildStarted();
project.init();
ProjectHelper projectHelper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", projectHelper);

projectHelper.parse(project, buildFile);
project.setNewProperty("test", className.trim());
if (!(methodName.equals(""))) {
project.setNewProperty("method", methodName.trim());
}
if ("debug".equals(mode)) {
project.setNewProperty("debug", "true");
}

project.executeTarget("test");
project.fireBuildFinished(null);
project.getBuildListeners();
out.println("------------- Start Run Test Case -------------");
out.println( MyLogger.completeMessage);
out.println("------------- End Run Test Case -------------");

success = true;
} catch (BuildException buildException) {
project.fireBuildFinished(buildException);
}

return success;
}

private MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}

}

我使用上面的代码在给定的 build.xml 中运行 ant 目标。这个构建 xml 使用 ant-contrib-1.0b1.jar 中的一些任务。

projectHelper.parse(project, buildFile);

此解析方法返回以下异常

构建失败/home/sg40304/Projects/modularization/modules/core/system-testing/build.xml:19: 执行此行时出现以下错误:/home/sg40304/Projects/modularization/project-properties.xml:183: 执行此行时出现以下错误:/home/sg40304/Projects/modularization/project-deps.xml:17: 执行此行时出现以下错误:/home/sg40304/Tools/build-tools/build/deps.xml:18:无法在 ${ant.home}/lib 中找到 ant-contrib(1.0b2 或更高版本)。 ant-contrib 可从 http://ant-contrib.sourceforge.net/ 获得

谁能帮我解决这个问题;(

最佳答案

在机器上安装 ant-contrib

说明在下面的链接中给出

http://ant-contrib.sourceforge.net/

关于java - 通过eclipse插件执行ant Target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13413115/

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