0
votes

I currently have a Maven application within Netbeans. Since I need to use regular expressions within my project, I added the following class to one of my packages : http://docs.oracle.com/javase/tutorial/essential/regex/test_harness.html

I changed all the Input/Output statements to use System.out and BufferedReader. When I run this class from a fresh project, the class works as expected. But when I add it to my Maven project, I can see no output after :

NetBeans: Executing '/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

Scanning for projects...


Building crawler4j task-segment: [process-classes, org.codehaus.mojo:exec-maven-plugin:1.1.1:exec]


[enforcer:enforce]

[resources:resources]

Using 'UTF-8' encoding to copy filtered resources.

Copying 2 resources

[compiler:compile]

Compiling 1 source file to /home/gowri/WORKSPACE/yasserg-crawler4j-7b8bf91/target/classes

[exec:exec]

Could anyone please tell me why this is happening ? I made sure that this class is the only one with a main() function in it, and I click on "Run file" and not on "Run Project".

Thank you :)

EDIT : I just realized something, when I convert all the System.out.print() statements to System.out.println(), only then can I see the correct output. Any ideas why ?

1

1 Answers

2
votes

The problem seems to be the detached System.in or System.out from the Output window while using maven in Netbeans as pointed out in this issue. Try updating the exec-maven-plugin to 1.2 in the nbactions.xml file in your current Project directory, this bug has been solved in this newer version.

To do that with UI, go to Project->Properties->Actions-> In the action: Run File via main(), Change the excecute goals to something like this: "process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec"

After doing so, your nbactions.xml should have an action tag which would look like:

    <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>