Broken console in Maven project using Netbeans

我是研究僧i 提交于 2020-01-04 08:28:04

问题


I have strange problem with my Neatens+Maven installation. This is the shortest code to reproduce the problem:

public class App 
{
    public static void main( String[] args )
    {
           // Create a scanner to read from keyboard
    Scanner scanner = new Scanner (System.in);

   Scanner s= new Scanner(System.in);
    String param= s.next();
    System.out.println(param);
    }
}

When I'm running it as Maven Project inside Netbeans console seems to be broken. It just ignores my input. It's look like "infinitive loop" in String param= s.next(); (or like String param= s.next(); placed in infinitive loop)

However this project works fine when it's compiled as "Java Aplication" project. It also works O.K. if I build and run it from cmd.

System info: Os: Vista IDE: Netbeans 6.8 Maven: apache-maven-2.2.1

//edit

Built program (using mavean from Netbeans) works fine (I can run it from Windows cmd). I just can't test it (Run nor debug :() using Netbeans.

And I think I forgot to ask the question ;). So of course my first question is: how can I fix this problem?

And second is: Is it any workaround for this? For example configuring Netbeans to run external commend line app instead of using built in console.

//edit one more update:

I use Exec Maven Plugin version 1.1.1 Problem also occurs in NB 6.9 RC2. In both NB versions (6.8 and 6.9 RC2) I tested maven 3.0-beta-1 and maven-2.2.1 with the same result.


回答1:


I recall fixing some similar problem a while back, can't recall if it was before or after 6.8. The problem is two fold, there's input conversion within the maven build itself (as it's running the app in forked process/different jvm. then in netbeans console we again have to to the input piping again.

please check that you are using the latest released exec-maven-plugin. You can also reach the netbeans issuetracking for that problem, I'm sure you might get more context there.




回答2:


You can use the exec goal exec:java to run the app in the same vm (default is exec:exec - new vm).




回答3:


I just encountered the same problem when using NetBeans 6.9.1 and Maven 3.0.2.

This was a bug documented in Netbeans here at: netbeans community

As it turns out the issue was with the org.codehaus.mojo:exec-maven-plugin which was fixed in version 1.2.

To remedy this in netbeans you can change your nbactions.xml file in the root directory of your project to

        <goals>
            <goal>process-classes</goal>
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
        </goals>

or modify the project properties under 'Actions':

  • Select 'Run Project'
  • change the Execute goals to "process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec " Do the same for the goals in "run File via main()"


来源:https://stackoverflow.com/questions/3035351/broken-console-in-maven-project-using-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!