9

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?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Mitch Haraldsson
  • 151
  • 2
  • 10

4 Answers4

6

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");
Marcus
  • 1,857
  • 4
  • 22
  • 44
  • It's been a while now so I do not have the code anymore i tested with and I can't tell you what I did wrong. However, this works perfectly fine. Thank you very much! Finally colored output :) – Mitch Haraldsson Oct 27 '15 at 09:16
  • I did some tests and apparently the colors work, but not the clear screen! https://github.com/ramonchiara/Cores – Ramon Chiara Nov 29 '18 at 15:05
2

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

See:

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>
tomorrow
  • 1,260
  • 1
  • 14
  • 26
  • An alternative fix is to simply remove jansi. On my Linux box I did `chmod -r /path/to/netbeans/java/maven/lib/jansi*` and bug seems to be gone, without advesary effects until now (but I'm not a heavy Netbeans user) – YoungFrog Nov 25 '21 at 09:10
1

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

user427843
  • 91
  • 1
  • 5
0

@YoungFrog solution was the best for me.

I spent all day to get NetBeans 14 working with hyperlinks and ANSI colors simultaneosly.

chmod -r /path/to/netbeans-14/netbeans/java/maven/lib/jansi*

did the job.

Actually, for me it was bad to change the default maven installation folder. In order to have all the output correctly working (hyperlinks in stack trace, ANSI colors in output, no NETBEANS-EXEC lines) I suggest you to use the one bundled with the specific NetBeans version you have installed.