System.out.print() invisible until new line in exec-maven-plugin

194 Views Asked by At

This is very strange, and now i explain this with detail. I am in Intellij Idea 2021.3, i make a Maven project, with jdk Amazon-corretto-11. I use the plugin org.codehaus.mojo:exec-maven-plugin to run the program, and this is the program:

public static void main(String[] args) throws InterruptedException {
    System.out.println("hello");
    System.out.print("ok");
    Thread.sleep(2000);
}

The fact is, that it correctly prints "hello", but i do not see "ok" until the program ends or a new line is printed. I tried this in a classic project (no maven) and the "ok" appears instantly. pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>TempTest</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <JAVA_HOME>C:\Users\user\.jdks\corretto-11.0.12</JAVA_HOME>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <arguments>
                            <argument>--module-path</argument>
                            <!-- automatically creates the modulepath using all project dependencies, also adding the project build directory -->
                            <modulepath/>
                            <argument>-classpath</argument>
                            <!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
                            <classpath/>
                            <argument>com.gabrik.TempTest</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <executable>${JAVA_HOME}/bin/java</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

Any help would be appreciated, note that this weird thing ONLY happens if i am in a maven project AND i run with org.codehaus.mojo:exec-maven-plugin, otherwise the text "ok" appears. I tried to reboot my pc, to create another project repeating the same steps, but the problem persists

0

There are 0 best solutions below