与Maven的Netbeans - 奇怪的类行为

时间:2012-03-15 14:38:49

标签: maven netbeans

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

我更改了所有的Input / Output语句以使用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 process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec' NetBeans:JAVA_HOME = / home / gowri / jdk1.6.0_20

扫描项目......


构建crawler4j    任务段:[process-classes,org.codehaus.mojo:exec-maven-plugin:1.1.1:exec]


[实施者:强制]

[资源:资源]

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

复制2个资源

[编译器:编译]

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

[exec:exec]

有谁能告诉我为什么会这样?我确保这个类是唯一一个带有main()函数的类,我点击“Run file”而不是“Run Project”。

谢谢:)

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

1 个答案:

答案 0 :(得分:2)

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

要使用UI执行此操作,请转到Project-> Properties-> Actions-> 在行动中: 通过main()运行File, 将执行目标更改为以下内容: “process-classes 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>