Skip to content

Instantly share code, notes, and snippets.

@md5
Last active October 17, 2018 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md5/7fb07efafee3802da457 to your computer and use it in GitHub Desktop.
Save md5/7fb07efafee3802da457 to your computer and use it in GitHub Desktop.

Clone this gist:

$ git clone https://gist.github.com/7fb07efafee3802da457.git java-8-jre-font-test

Change to the test directory:

$ cd java-8-jre-font-test

Default test runs with java:8-jre:

$ ./test.sh

Run with java:7-jre:

$ ./test.sh 7

Run with java:8-jdk:

$ ./test.sh 8-jdk
import java.awt.*;
import java.io.*;
public class Test {
public static void main(String... argz) throws Exception {
boolean headless = GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadless();
System.out.println(String.format("Headless: %s", headless));
Font.createFont(Font.TRUETYPE_FONT, new File("test.ttf")).deriveFont(Font.TRUETYPE_FONT, 20F);
}
}
#!/bin/bash
set -ueo pipefail
RUN_IMAGE="java:8-jre"
if [ $# -gt 0 ]; then
RUN_IMAGE="$1"
fi
if ! [[ "$RUN_IMAGE" = java:* ]]; then
RUN_IMAGE="java:$RUN_IMAGE"
fi
if ! [[ "$RUN_IMAGE" = *-* ]]; then
RUN_IMAGE+="-jre"
fi
if [[ "$RUN_IMAGE" = *-jdk ]]; then
COMPILE_IMAGE="${RUN_IMAGE}"
else
COMPILE_IMAGE="${RUN_IMAGE%-jre}-jdk"
fi
PWD="$(pwd)"
set -x
rm -f Test*.class
docker pull "$COMPILE_IMAGE" > /dev/null
docker run --rm -v "$PWD:/work" -w /work "$COMPILE_IMAGE" javac Test.java
docker pull "$RUN_IMAGE" > /dev/null
docker run --rm -v "$PWD:/work" -w /work "$RUN_IMAGE" java -cp . Test || \
docker run --rm -v "$PWD:/work" -w /work "$RUN_IMAGE" sh -c ' \
set -x \
&& apt-get update \
&& apt-get install -y libfontconfig1 \
&& java -cp . Test \
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment