Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MavenCli输出到eclipse/maven控制台_Java_Eclipse_Maven_Eclipse Rcp_M2eclipse - Fatal编程技术网

Java MavenCli输出到eclipse/maven控制台

Java MavenCli输出到eclipse/maven控制台,java,eclipse,maven,eclipse-rcp,m2eclipse,Java,Eclipse,Maven,Eclipse Rcp,M2eclipse,我有一个elipse RCP应用程序,它使用Maven Surefire进行特殊测试。 Maven通过m2e集成到应用程序中 用户在我的应用程序中构建他的项目,并希望测试他的部分项目 现在可以从我的代码中启动maven test命令,它工作得很好,但是日志输出不是打印到我的应用程序控制台,而是打印到我的IDE控制台 public class MyAction implements IObjectActionDelegate { private IFolder selectedFolder; p

我有一个elipse RCP应用程序,它使用Maven Surefire进行特殊测试。 Maven通过m2e集成到应用程序中

用户在我的应用程序中构建他的项目,并希望测试他的部分项目

现在可以从我的代码中启动maven test命令,它工作得很好,但是日志输出不是打印到我的应用程序控制台,而是打印到我的IDE控制台

public class MyAction implements IObjectActionDelegate {

private IFolder selectedFolder;
private IPath path;

@Override
public void run(IAction action) {
    String flagValue = foo();
    String projectLocation = bar();

    PrintStream out = System.out; // <- here

    MavenCli cli = new MavenCli();
    cli.doMain(new String[] {"test", "-DmyFlag=" + flagValue}, 
            projectLocation, out, out);
}
公共类MyAction实现IObjectActionDelegate{
专用IFolder Selected文件夹;
专用IPath路径;
@凌驾
公开作废运行(IAction行动){
字符串flagValue=foo();
字符串projectLocation=bar();

PrintStream out=System.out;//好的,我找到了一种从MavenCLI打印到应用程序控制台的方法。在用户触发的操作中,我正在启动作业:

public class MyAction implements IObjectActionDelegate {

private IFolder selectedFolder;
private IPath path;

@Override
public void run(IAction action) {
    String flagValue = foo();
    String projectLocation = bar();

    MyJob runTestCaseJob = new MyJob(flagValue , projectLocation);
        runTestCaseJob.schedule();
}
在职业课上,我开始学习MavenCLI:

public class MyJob extends Job {

private static final String TASK_NAME = "Starting the Maven Command";

private String myFlag;
private String projectLocation;

private final PrintStream out = getConsole();
private final MavenCli cli = new MavenCli();

public MyJob(String myFlag, String projectLocation) {
    super(TASK_NAME);
    this.myFlag = myFlag;
    this.projectLocation = projectLocation;
}

@Override
protected IStatus run(IProgressMonitor monitor) {
    cli.doMain(new String[] {"test", "-DmyFlag=" + myFlag}, 
            projectLocation, out, out);
    return Status.OK_STATUS;
}

private PrintStream getConsole() {
    MessageConsole console = findMessageConsole("Console");
    console.activate();
    return new PrintStream(console.newOutputStream());
}

private MessageConsole findMessageConsole(String title) {
    IConsole[] existingConsoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles();
    for (IConsole existingConsole : existingConsoles) {
        if (existingConsole.getName().equals(title)) {
            return (MessageConsole) existingConsole;
        }
    }
    MessageConsole console = new MessageConsole(title, null);
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
    return console;
}

为什么要调用Maven命令行,而不是像您前面提到的那样使用与surefire相关的常规单元/集成测试设置?我希望用户能够测试他在我的应用程序中创建的项目。他在项目的pom文件中指定依赖项和属性,并可以运行Maven surefire测试。