使用 Netbeans 的 Maven 项目中的控制台损坏

发布于 2024-09-05 17:30:25 字数 1050 浏览 1 评论 0原文

我的 Neatens+Maven 安装遇到了奇怪的问题。这是重现该问题的最短代码:

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);
    }
}

当我在 Netbeans 控制台内将其作为 Maven 项目运行时,它似乎已损坏。它只是忽略我的输入。它看起来像 String param= s.next(); 中的“不定式循环”(或者像 String param= s.next(); 放置在不定式循环中)

但是这个当项目编译为“Java Aplication”项目时,它可以正常工作。如果我从 cmd 构建并运行它,它也可以正常工作。

系统信息: 操作系统:Vista IDE:Netbeans 6.8 Maven:apache-maven-2.2.1

//edit

构建的程序(使用 Netbeans 中的 mavean)工作正常(我可以从 Windows cmd 运行它)。我只是无法使用 Netbeans 测试它(运行或调试:()。

而且我想我忘了问这个问题;)。当然,我的第一个问题是:我该如何解决这个问题?

第二个问题是:有解决办法吗?例如,将 Netbeans 配置为运行外部命令行应用程序,而不是使用内置控制台。

//编辑 还有一个更新:

我使用 Exec Maven Plugin 版本 1.1.1 NB 6.9 RC2 中也出现此问题。在两个NB版本(6.8和6.9 RC2)中,我测试了maven 3.0-beta-1和maven-2.2.1,结果相同。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生共白头 2024-09-12 17:30:25

我记得不久前修复过一些类似的问题,不记得是在6.8之前还是之后。
问题有两个方面,maven 构建本身存在输入转换(因为它在分叉进程/不同的 jvm 中运行应用程序)。
然后在 netbeans 控制台中,我们再次必须再次输入管道。

请检查您是否使用最新发布的 exec-maven-plugin。您还可以访问 netbeans 问题跟踪来解决该问题,我相信您可能会在那里获得更多背景信息。

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.

挖鼻大婶 2024-09-12 17:30:25

您可以使用 exec 目标 exec:java 在同一虚拟机中运行应用程序(默认为 exec:exec - 新虚拟机)。

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

梦忆晨望 2024-09-12 17:30:25

我刚刚在使用 NetBeans 6.9.1 和 Maven 3.0.2 时遇到了同样的问题。

网址为:netbeans 社区

这是 Netbeans 中记录的一个错误, 问题出在 org.codehaus.mojo:exec-maven-plugin 上,该问题已在 1.2 版中修复。

要在 netbeans 中解决此问题,您可以将项目根目录中的 nbactions.xml 文件更改为

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

或修改“操作”下的项目属性:

  • 选择“运行项目”,
  • 将执行目标更改为“process-classes org.codehaus.mojo” :exec-maven-plugin:1.2:exec " 对“通过 main() 运行文件”中的目标执行相同的操作

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()"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文