Set -Djava.awt.headless=true did not help in my case. I had to modify the Java code to make it work. Two key changes:
1: do not use Graphics object in ImageGenerator.java
2: do not use BasicEncoder.encode(BufferedImage bufferedImage, OutputStream outputStream,
float quality, String format) method, use ImageIO.write(bufferedImage, format, outputStream) instead