For those kind of projects use Ant or Gradle. They do not suffer from this
issue, and probably better suited for small student projects.

On Sat, Aug 28, 2021, 13:16 David Green <dgreen...@gmail.com> wrote:

> Thanks for the reply and insight.
>
> That does work at the command line (as did running it from a jar file).  I
> am seeking to have it work in the NetBeans Output window and I found that
> if I edited the Run (and Run File) Actions in the project properties to use
> "java" instead of "exec", it does work.  It did generate a nbactions.xml
> file that was not there before.
>
> Should this be the default behavior when one generates Java with Maven |
> Java Application?  I am looking for configurations to use with students who
> are learning the language and OO thinking and don't want to add any more
> friction than necessary.
>
> Are there any downsides of making this change?
>
> Dave
>
>
>
>
>
>
>
> On Sat, Aug 28, 2021 at 2:15 PM Vladimir Machat <macha...@gmail.com>
> wrote:
>
> > Hi,
> >
> > i believe it's exec:exec maven target problem, because if you run the
> > same code with exec:java it works perfectly, even without the flush()
> >
> > try 'mvn exec:java -Dexec.mainClass=dgreen.printbug.NewMain' from
> > command line
> >
> > On 28/08/2021 18:54, David Green wrote:
> > > In NetBeans 12.4 and verified to also behave this way on NetBeans
> > > 12.5-beta2, System.out.print is buffered such that it does not show up
> in
> > > the NetBeans Output window until a System.out.println (or probably
> things
> > > like program end, and some buffer full scenario).
> > >
> > > Using JDK 15 and a Maven Project.  I am using macOS but my students who
> > hit
> > > this problem are using Windows.
> > >
> > > Example code:
> > >
> > > package dgreen.printbug;
> > >
> > > import java.util.Scanner;
> > >
> > > /**
> > >   * Demo program showing that System.out.print's are not pushed to
> output
> > > window until a
> > >   * System.out.println
> > >   */
> > > public class NewMain {
> > >
> > >    /** @param args the command line arguments */
> > >    public static void main(String[] args) {
> > >      Scanner sc = new Scanner(System.in);
> > >      System.out.print("Enter your name: ");
> > >      System.out.flush(); // should not be necessary but does not work
> > either
> > >      String name = sc.nextLine();
> > >      System.out.println("Hi " + name);
> > >    }
> > > }
> > >
> > > —-
> > > Running it after Clean & Build (or before)
> > >
> > > --- exec-maven-plugin:3.0.0:exec (default-cli) @ printbug ---
> > > dave
> > > Enter your name: Hi dave
> > >
> ------------------------------------------------------------------------
> > > BUILD SUCCESS
> > >
> > > where "dave" was typed in without the benefit of seeing the prompt.
> > >
> > > This works fine when run from true command line either inside a
> NetBeans
> > > Terminal Window or the real command line.
> > >
> > > In Jira as https://issues.apache.org/jira/browse/NETBEANS-5961
> > >
> > > Dave
> > >
> >
>

Reply via email to