diff --git a/tutorials/docker/Dockerfile b/tutorials/docker/Dockerfile index ffc110f..cb4384b 100644 --- a/tutorials/docker/Dockerfile +++ b/tutorials/docker/Dockerfile @@ -1,34 +1,34 @@ -FROM ubuntu:20.04 +FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive -ENV TZ=UTC RUN apt update # Install JDK. -RUN apt install -y openjdk-8-jdk +RUN apt install -y openjdk-17-jdk # Install Chromium's runtime dependencies. RUN apt install -y \ - libasound2 \ + ca-certificates \ + fonts-liberation \ + libasound2t64 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libatspi2.0-0 \ libc6 \ - libcairo2 \ + libcairo2 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libexpat1 \ - libfontconfig1 \ libgbm1 \ - libgcc-s1 \ libglib2.0-0 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libpango-1.0-0 \ - libpulse0 \ + libu2f-udev \ + libvulkan1 \ libx11-6 \ libxcb1 \ libxcomposite1 \ @@ -36,10 +36,7 @@ RUN apt install -y \ libxext6 \ libxfixes3 \ libxkbcommon0 \ - libxrandr2 \ - libxshmfence1 \ - libxtst6 \ - xdg-utils + libxrandr2 # Install a virtual X11 server that is required for Chromium to work. RUN apt install -y xvfb @@ -56,5 +53,6 @@ COPY project/ project # Build the Java project. RUN cd project && ./gradlew build +# Set the working directory and the entrypoint. WORKDIR / ENTRYPOINT ["sh", "-c", "/startup.sh"] diff --git a/tutorials/docker/project/build.gradle.kts b/tutorials/docker/project/build.gradle.kts index 0afb7e9..10d75c5 100644 --- a/tutorials/docker/project/build.gradle.kts +++ b/tutorials/docker/project/build.gradle.kts @@ -22,7 +22,7 @@ plugins { java application // Provides convenience methods for adding JxBrowser dependencies into a project. - id("com.teamdev.jxbrowser") version "1.1.0" + id("com.teamdev.jxbrowser") version "2.0.0" } application { @@ -33,11 +33,17 @@ repositories { mavenCentral() } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + jxbrowser { - version = "7.41.0" + version = "8.16.1" } dependencies { implementation(jxbrowser.swing) - implementation(jxbrowser.linux64) + implementation(jxbrowser.currentPlatform) } diff --git a/tutorials/docker/project/src/main/java/DemoApp.java b/tutorials/docker/project/src/main/java/DemoApp.java index 9cfeafc..58d25e4 100644 --- a/tutorials/docker/project/src/main/java/DemoApp.java +++ b/tutorials/docker/project/src/main/java/DemoApp.java @@ -42,18 +42,20 @@ public final class DemoApp { public static void main(String[] args) { // Set your JxBrowser license key. - System.setProperty("jxbrowser.license.key", "ENTER YOUR LICENSE KEY HERE"); + System.setProperty("jxbrowser.license.key", "YOUR_LICENSE_KEY"); - EngineOptions.Builder options = EngineOptions.newBuilder(HARDWARE_ACCELERATED); + var options = EngineOptions.newBuilder(HARDWARE_ACCELERATED); - // #docfragment "enable-remote-debugging-port" // Enable the remote debugging port. + options.addSwitch("--remote-allow-origins=http://localhost:9222"); options.remoteDebuggingPort(9222); - // #enddocfragment "enable-remote-debugging-port" + + // Disable Chromium sandbox for Docker. + options.disableSandbox(); // Creating Chromium engine. - Engine engine = Engine.newInstance(options.build()); - Browser browser = engine.newBrowser(); + var engine = Engine.newInstance(options.build()); + var browser = engine.newBrowser(); // Print the web page's title once the page is loaded. browser.navigation().on(LoadFinished.class, event -> { @@ -61,8 +63,8 @@ public static void main(String[] args) { }); SwingUtilities.invokeLater(() -> { - final BrowserView view = BrowserView.newInstance(browser); - JFrame frame = new JFrame("Demo App"); + var view = BrowserView.newInstance(browser); + var frame = new JFrame("Demo App"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { diff --git a/tutorials/docker/startup.sh b/tutorials/docker/startup.sh index 039c68d..d85163d 100644 --- a/tutorials/docker/startup.sh +++ b/tutorials/docker/startup.sh @@ -20,10 +20,16 @@ # # Launch a virtual X11 server for Chromium. -Xvfb :0 -screen 0 800x600x24+32 & +# +# If DISPLAY is not set, start a virtual X server (headless mode). +# If DISPLAY is set, connect to the host X server (desktop mode). +if [ -z "${DISPLAY:-}" ]; then + Xvfb :0 -screen 0 1920x1080x24+32 & + export DISPLAY=:0 +fi # Switch to the project directory. cd project # Start the Java application. -DISPLAY=:0 ./gradlew run +./gradlew run