0

I have a BufferedImage object, created from ByteArrayInputStream with (ImageIO/read) function. Now I want to paint some lines on this image, so at the beginning I create Graphics2d object like this:

(defn g2d (.createGraphics image))

And here strange thing happens, because my function freezes here in this step. It never returns, never throws an Exception nothing. I run this program on server:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

How could I find a cause of this freeze? I also checked if this Java version is headless like this:

(java.awt.GraphicsEnvironment/isHeadless)

But that method returned false.

polis
  • 795
  • 7
  • 23
  • 1
    if it's not headless, it will try to setup an Xserver (or something of that sort). Do you have xvfb installed? – Jochen Bedersdorfer Jul 06 '20 at 18:18
  • I'm not sure. Could you explain your idea? – polis Jul 06 '20 at 18:34
  • if you use the Graphics API, Java wants to set up a graphical system. That's what is taking so long and it might fail (I don't know your Linux setup). As an alternative, use a virtual graphics environment. (like xvfb). Maybe this will help: https://stackoverflow.com/questions/39388037/java-awt-requires-x11-how-to-use-xvfb-ubuntu-14-04 – Jochen Bedersdorfer Jul 06 '20 at 22:34
  • This article from Oracle might come handy for a headless example on plain Java, which you can rewrite in Clojure: https://www.oracle.com/technical-resources/articles/javase/headless.html – Denis Fuenzalida Jul 07 '20 at 01:32
  • Also check this answer for how to properly set headless mode programatically (if you are not passing the option from the command line): https://stackoverflow.com/a/2552470/483566 – Denis Fuenzalida Jul 07 '20 at 01:33

1 Answers1

1

Actually I had to write a separate Java program in order to see what was the problem. After seeing the Java exception I managed to solve this problem by unsetting Linux variable DISPLAY: unset DISPLAY.

polis
  • 795
  • 7
  • 23