如何阻止在Netbeans中开始的maven项目 [英] How to stop a maven project started in Netbeans

查看:276
本文介绍了如何阻止在Netbeans中开始的maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NetBeans中有一个以main函数开头的项目,它接受参数。当我点击停止按钮时,项目继续运行,但不再有输出。
目前我必须记住从控制台手动停止进程。



如何修改我的项目,maven设置或NetBeans配置以使进程停止当我点击停止时。



我可以使用没有终结器或ShutdownHooks调用的进程。



考虑这个类:

  public class Main {
public static void main(String [] args){
System.out.println(args:+ Arrays.asList(args));
new Main()。action();
}

private void action(){
Date start = new Date();
long endTime = start.getTime()+ 600000;
日期结束;
do {
synchronized(Thread.currentThread()){
try {
Thread.currentThread()。wait(1000);
System.out.println(PING);
} catch(InterruptedException iex){
return;
}
}
end = new Date();
} while(end.getTime()< endTime);
}
}

我希望它只使用NetBeans停止按钮消亡。

解决方案

当你在NetBeans输出中点击停止时,NB会停止maven进程,但是maven已经产生了实际的程序输出,所以stop命令不会移交给你的程序。



默认情况下,NetBeans使用'exec'目标调用exec-maven-plugin。如果将其更改为java目标,则没有新进程。在下面的更改之后,项目属性中的运行部分将为空且无用。我没有测试在这种情况下调用'System.exit'或类似的情况会发生什么。



另请注意,您必须注意修改版本号从现在开始单独使用。



您必须转到项目窗口,右键单击您的项目,转到属性并选择操作元素和运行项目条目。它将如下所示:





从现在开始,Maven不会分叉一个新进程,所以当你点击停止时它实际上会停止专业cess。


I have a project in NetBeans that starts with a main function, that takes arguments. When I hit the "Stop" Button, the project continues running, but there is no output anymore. Currently I have to remember to manually stop the process from the console.

How can I modify my project, maven setup or NetBeans configuration to make the process halt when I hit stop.

I can live with the process not having its finalizers or ShutdownHooks called.

Consider this class:

public class Main {
    public static void main(String[] args) {
        System.out.println("args: " + Arrays.asList(args));
        new Main().action();
    }

    private void action() {
        Date start = new Date();
        long endTime = start.getTime() + 600000;
        Date end;
        do {
            synchronized (Thread.currentThread()) {
                try {
                    Thread.currentThread().wait(1000);
                    System.out.println("PING");
                } catch (InterruptedException iex) {
                    return;
                }
            }
            end = new Date();
        } while (end.getTime() < endTime);
    }
}

I want it to die using only NetBeans Stop button.

解决方案

When you hit "Stop" in the NetBeans output, NB stops the maven process, but maven had spawned the actual program output, so the stop command is not handed over to your program.

NetBeans calls the exec-maven-plugin with the 'exec' goal by default. If you change it to the 'java' goal there is no new process. After the change below, the 'Run' section in your projects 'Properties' will be empty and of no use. I did not test what happens if you call 'System.exit' or similar in this scenario.

Also note, that you have to take care that you modify the version number here by yourself from now on.

You have to go to Projects window, right click your project, go to the Properties and select the Actions element and the the Run project entry. It will look like this:

You have to modify

  1. Execute Goals: to process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:java (change the exec in the end to java).
  2. Set Properties: to exec.mainClass=de.steamnet.stopfromnetbeans.Main exec.classpath=%classpath exec.args=First Second 'Third Space'

So that it looks like this:

From now on, Maven will not fork a new process, so when you hit "Stop" it will actually Stop the process.

这篇关于如何阻止在Netbeans中开始的maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆