Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colored output in netbeans console with ansicodes

I am trying to get a colored output in my Netbeans output window.

Ansi-Output in Linux and Windows console works perfectly fine. However not in the IDE.

Is there a way to make this work in Netbeans' output window?

According to this https://netbeans.org/bugzilla/show_bug.cgi?id=214546 it should work, but it doesn't in my current Netbeans 8.0.1 installation (neither Linux nor Windows).

Any hints on how to do that?

like image 698
Mitch Haraldsson Avatar asked Oct 17 '14 13:10

Mitch Haraldsson


People also ask

How do I change the color of a terminal in NetBeans?

I went to tools->options->miscellaneous->output and changed the background color. :) great..

Why I am not getting output in NetBeans?

Try to run the code on cmd and try. If it runs successfully, check if you are executing the java class or the project in total. That may be the reason of no output. Else then try reinstalling your NetBeans IDE.


3 Answers

I am using Netbeans 8.0.1 myself, on Windows 7. I just tried ANSI escape code, and it works. Example:

String greenBold = "\033[32;1m";
String reset = "\033[0m";
System.out.println("before" + greenBold + " green " + reset + "after");
like image 198
Marcus Avatar answered Sep 28 '22 00:09

Marcus


There seems to be a problem when using Maven 3.5.x.

See:

  • https://netbeans.org/bugzilla/show_bug.cgi?id=270593
  • https://github.com/fusesource/jansi/issues/87

I tried NB 8.2 with the old Maven 3.3.9 first and it worked fine out of the box. The whole output remained as it had been but my application's own logs were colored as expected.

With Maven 3.5.2 and 3.5.4 the colors didn't work at all. So I had to set MAVEN_OPTS environment variable to "-Djansi.passthrough=true" (as suggested in the first link) and restart NetBeans. The problem is that now the whole output is colored differently and error stack traces don't contain links to code any more. So I'm switching back.

BTW. When using log4j2's %highlight{}, I also had to set disableAnsi="false" to get the desired effect:

<Console name="Console" target="SYSTEM_OUT">
    <PatternLayout pattern="%d{HH:mm:ss.SSS} %highlight{%-5level} [%t] %location --- %msg%n%throwable" disableAnsi="false" />
</Console>
like image 36
tomorrow Avatar answered Sep 28 '22 00:09

tomorrow


I'm using NetBeans 12.3 and I had same problem. Problem is with bundled Maven (version 3.6.3). When I changed to Maven which I installed on my system it works. Note that version of Maven installed on my system is the same as the bundled one - 3.6.3.

enter image description here

I have changed location of Maven in settings: enter image description here

like image 21
user427843 Avatar answered Sep 28 '22 00:09

user427843