【问题标题】:Netbeans with Maven - Strange class behaviour带有 Maven 的 Netbeans - 奇怪的类行为
【发布时间】:2012-03-15 14:38:48
【问题描述】:

我目前在 Netbeans 中有一个 Maven 应用程序。由于我需要在我的项目中使用正则表达式,我将以下类添加到我的一个包中:http://docs.oracle.com/javase/tutorial/essential/regex/test_harness.html

我将所有输入/输出语句更改为使用 System.out 和 BufferedReader。当我从一个新项目运行这个类时,该类按预期工作。但是当我将它添加到我的 Maven 项目时,我看不到任何输出:

NetBeans:执行 '/usr/share/maven2/bin/mvn -Dexec.classpathScope=runtime -Dexec.args=-classpath %classpath MySource.RegexTestHarness -Dexec.executable=/home/gowri/jdk1.6.0_20/ bin/java -Dnetbeans.execution=true 进程类 org.codehaus.mojo:exec-maven-plugin:1.1.1:exec' NetBeans:JAVA_HOME=/home/gowri/jdk1.6.0_20

正在扫描项目...


构建 crawler4j 任务段:[进程类,org.codehaus.mojo:exec-maven-plugin:1.1.1:exec]


[执行者:执行]

[资源:资源]

使用“UTF-8”编码复制过滤后的资源。

复制 2 个资源

[编译器:编译]

将 1 个源文件编译到 /home/gowri/WORKSPACE/yasserg-crawler4j-7b8bf91/target/classes

[执行:执行]

谁能告诉我为什么会这样?我确保这个类是唯一一个包含 main() 函数的类,我点击“运行文件”而不是“运行项目”。

谢谢你:)

编辑:我刚刚意识到,当我将所有 System.out.print() 语句转换为 System.out.println() 时,我才能看到正确的输出。任何想法为什么?

【问题讨论】:

    标签: maven netbeans


    【解决方案1】:

    问题似乎是在 issue 中指出的在 Netbeans 中使用 maven 时从输出窗口分离的 System.in 或 System.out。尝试将当前项目目录中 nbactions.xml 文件中的 exec-maven-plugin 更新为 1.2,此错误已在此新版本中解决。

    要使用 UI 执行此操作,请转到 Project->Properties->Actions-> 在行动中: 通过 main() 运行文件, 将执行目标更改为以下内容: "进程类 org.codehaus.mojo:exec-maven-plugin:1.2:exec"

    完成此操作后,您的 nbactions.xml 应该有一个如下所示的操作标记:

        <action>
            <actionName>run.single.main</actionName>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
            </goals>
            <properties>
                <exec.classpathScope>${classPathScope}</exec.classpathScope>                
                <exec.args>-Djava.library.path="${project.build.directory}/lib" -classpath %classpath ${packageClassName}</exec.args>
                <exec.executable>java</exec.executable>
            </properties>
        </action>
        <action>
            <actionName>debug.single.main</actionName>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
            </goals>
            <properties>
                <exec.classpathScope>${classPathScope}</exec.classpathScope>
                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName}</exec.args>
                <jpda.listen>true</jpda.listen>
                <jpda.stopclass>${packageClassName}</jpda.stopclass>
                <exec.executable>java</exec.executable>
            </properties>
        </action>  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 2011-08-07
      • 1970-01-01
      • 2012-11-12
      • 2019-08-19
      相关资源
      最近更新 更多