JxBrowser 7 的支持将于 2025 年 10 月终止,届时将不再提供 Chromium 更新和关键修复。
我们建议您升级至 JxBrowser 8,以享受新功能和改进带来的更多优势。
如果您有任何疑问或在升级过程中需要帮助,欢迎随时 。
配置 Gradle 项目
本页介绍如何将 JxBrowser 添加到 Gradle 项目中。
要将 JxBrowser 添加到 Gradle 项目中,您必须在构建脚本文件 build.gradle(.kts) 中添加 JxBrowser Gradle 插件,并在那里配置项目的依赖项。
应用插件
要应用 JxBrowser Gradle 插件,请使用 Gradle DSL 中的 plugins 块:
Groovy
Kotlin
plugins {
    id 'com.teamdev.jxbrowser' version '2.0.0'
}
plugins {
    id("com.teamdev.jxbrowser") version "2.0.0"
}
配置插件
应用了插件后,可以通过 build.gradle(.kts) 文件中的 jxbrowser 扩展来配置该插件。
版本
使用 version 属性设置所需的库版本:
Groovy
Kotlin
jxbrowser {
    version = '7.44.2'
}
jxbrowser {
    version = "7.44.2"
}
version 属性是强制性的,省略它将导致 IllegalStateException。
存储库
您可以指定要使用的 JxBrowser 存储库的位置,可以是北美或欧洲:
Groovy
Kotlin
jxbrowser {
    version = '7.44.2'
    repository = Repository.EUROPE
}
jxbrowser {
    version = "7.44.2"
    repository = Repository.EUROPE
}
您还可以通过其 URL 指定自定义存储库,如下所示:
Groovy
Kotlin
jxbrowser {
    version = '7.44.2'
    repository = 'https://my.custom.repository'
}
jxbrowser {
    version = "7.44.2"
    repository = "https://my.custom.repository"
}
如果未指定 repository 属性,则位置将设置为北美。
预览版本
使用 includePreviewBuilds() 将包含 JxBrowser 预览版本的存储库添加到项目中。
Groovy
Kotlin
jxbrowser {
    version = '7.44.2'
    includePreviewBuilds()
}
jxbrowser {
    version = "7.44.2"
    includePreviewBuilds()
}
依赖项
跨平台
要添加适用于 Windows、macOS 和 Linux 的 JxBrowser 库,请添加以下代码:
Groovy
Kotlin
dependencies {
    implementation jxbrowser.crossPlatform
}
dependencies {
    implementation(jxbrowser.crossPlatform)
}
特定平台
如果您只需要特定平台的 JxBrowser JAR 文件,您可以使用如下所述的适当依赖项。
如果您的 Java 应用程序仅在 Windows 和 macOS 平台上运行,并且您不需要 Linux 依赖项,则可以只包含 Windows 和 macOS 依赖项。
Windows 32 位
Groovy
Kotlin
dependencies {
    implementation jxbrowser.win32
}
dependencies {
    implementation(jxbrowser.win32)
}
Windows 64 位
Groovy
Kotlin
dependencies {
    implementation jxbrowser.win64
}
dependencies {
    implementation(jxbrowser.win64)
}
macOS 64 位
Groovy
Kotlin
dependencies {
    implementation jxbrowser.mac
}
dependencies {
    implementation(jxbrowser.mac)
}
macOS 64 位 ARM
Groovy
Kotlin
dependencies {
    implementation jxbrowser.macArm
}
dependencies {
    implementation(jxbrowser.macArm)
}
Linux 64 位
Groovy
Kotlin
dependencies {
    implementation jxbrowser.linux64
}
dependencies {
     implementation(jxbrowser.linux64)
}
Linux 64 位 ARM
Groovy
Kotlin
dependencies {
    implementation jxbrowser.linuxArm
}
dependencies {
    implementation(jxbrowser.linuxArm)
}
当前平台
要检测当前平台并添加相应的 Chromium 二进制文件,请使用以下依赖项:
Groovy
Kotlin
dependencies {
    implementation jxbrowser.currentPlatform
}
dependencies {
    implementation(jxbrowser.currentPlatform)
}
GUI 工具箱
Swing
Groovy
Kotlin
dependencies {
    implementation jxbrowser.swing
}
dependencies {
    implementation(jxbrowser.swing)
}
JavaFX
Groovy
Kotlin
dependencies {
    implementation jxbrowser.javafx
}
dependencies {
    implementation(jxbrowser.javafx)
}
SWT
Groovy
Kotlin
dependencies {
    implementation jxbrowser.swt
}
dependencies {
    implementation(jxbrowser.swt)
}
总结
以下是 build.gradle(.kts) 的完整代码:
Groovy
Kotlin
import com.teamdev.jxbrowser.gradle.Repository
plugins {
    id 'java'
    id 'com.teamdev.jxbrowser' version '2.0.0'
}
jxbrowser {
    // JxBrowser 版本。必填字段。
    version = '7.44.2'
    // 要使用的 JxBrowser 存储库位置。要么是北美,要么是欧洲。
    // 如果未指定,位置将设置为北美。
    repository Repository.NORTH_AMERICA
    // 或者,它可以通过其 URL 指向自定义存储库,如下所示:
    // repository = "https://my.custom.repository"
    // 将带有 JxBrowser 预览版本的存储库添加到项目中。
    includePreviewBuilds()
}
dependencies {
    // 添加对核心 JxBrowser API 的依赖项。
    implementation jxbrowser.core
    // 为所有支持的平台添加对 Chromium 二进制文件的依赖项。
    implementation jxbrowser.crossPlatform
    // 添加对特定平台的 Chromium 二进制文件的依赖项。
    implementation jxbrowser.mac
    implementation jxbrowser.macArm
    implementation jxbrowser.win32
    implementation jxbrowser.win64
    implementation jxbrowser.linux64
    implementation jxbrowser.linuxArm
    // 检测当前平台并添加相应的 Chromium 二进制文件。
    implementation jxbrowser.currentPlatform
    // 添加对 UI 工具包集成的依赖项。
    implementation jxbrowser.swt
    implementation jxbrowser.swing
    implementation jxbrowser.javafx
}
import com.teamdev.jxbrowser.gradle.Repository
plugins {
    java
    id("com.teamdev.jxbrowser") version "2.0.0"
}
jxbrowser {
    // JxBrowser 版本。必填字段。
    version = "7.44.2"
    // 要使用的 JxBrowser 存储库位置。要么是北美,要么是欧洲。
    // 如果未指定,位置将设置为北美。
    repository = Repository.NORTH_AMERICA
    // 或者,它可以通过其 URL 指向自定义存储库,如下所示:
    // repository = "https://my.custom.repository"
    // 将带有 JxBrowser 预览版本的存储库添加到项目中。
    includePreviewBuilds()
}
dependencies {
    // 添加对核心 JxBrowser API 的依赖项。
    implementation(jxbrowser.core)
    // 为所有支持的平台添加对 Chromium 二进制文件的依赖项。
    implementation(jxbrowser.crossPlatform)
    // 添加对特定平台的 Chromium 二进制文件的依赖项。
    implementation(jxbrowser.mac)
    implementation(jxbrowser.macArm)
    implementation(jxbrowser.win32)
    implementation(jxbrowser.win64)
    implementation(jxbrowser.linux64)
    implementation(jxbrowser.linuxArm)
    
    // 检测当前平台并添加相应的 Chromium 二进制文件。
    implementation(jxbrowser.currentPlatform)
    
    // 添加对 UI 工具包集成的依赖项。
    implementation(jxbrowser.swt)
    implementation(jxbrowser.swing)
    implementation(jxbrowser.javafx)
}