Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions tutorials/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
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 \
libxdamage1 \
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
Expand All @@ -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"]
12 changes: 9 additions & 3 deletions tutorials/docker/project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
18 changes: 10 additions & 8 deletions tutorials/docker/project/src/main/java/DemoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,29 @@ 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 -> {
System.out.println("Title: " + browser.title());
});

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) {
Expand Down
10 changes: 8 additions & 2 deletions tutorials/docker/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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