Audio/Sound Output in IntelliJ IDEA on Linux with PulseAudio
A quick thing I just stumbled upon: Want to play a sound from a Java program using, for example, the
javax.sound APIs or the
Synthesizer but, when running from within IntelliJ IDEA, you can't hear a sound and see no exceptions?
First, try to package your project to create a
.jar file and execute it from a terminal. In my case, the same program that would not play a sound when executed from within IDEA, flawlessly played the sound when executed from within a terminal using
After a lot of Googling, I found out that IntelliJ IDEA can't connect to PulseAudio on Linux (at least Ubuntu 20.04 in my case) until you set the following environment variable:
You can set the variable in a run configuration like this:
I hope this saves someone else a lot of headaches.