如何使用JetBrains Runtime的一个模块

前端开发 2026-07-07

我想使用JetBrains Runtime的 JCEF模块(jbrsdk_jcef-25,版本25.0.3),但尝试编译时出现以下错误:

D:\cef2\src\main\java\module-info.java:5:14
java: module not found: jcef

我尝试过:

  • 临时删除 module-info.java 文件,因为IDE指出问题出在这里。这样只暴露了那些不可访问的单独类和包。
  • 通过从 pom.xml 删除某个依赖,可以重现该错误。这让我相信缺少一个依赖。
  • 我尝试从 maven仓库 添加该依赖,但编辑器(IntelliJ IDEA)提示找不到该依赖,未能解决问题。

为了测试,我使用IntelliJ的默认JavaFX Maven项目,替换默认的 start 方法和 pom.xml,改为如下:

public void start(Stage stage) {
    CefRendering rendering = CefRendering.DEFAULT;
    CefClient client = CefApp.getInstance().createClient();
    CefBrowser browser = client.createBrowser("https://google.com", rendering, false);
    SwingNode swingNode = new SwingNode();
    JPanel jPanel = new JPanel();
    jPanel.add(browser.getUIComponent());
    swingNode.setContent(jPanel);
    Scene scene = new Scene(new VBox(swingNode), 320, 240);
    stage.setTitle("Hello!");
    stage.setScene(scene);
    stage.show();
}
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

    <groupId>group</groupId>
    <artifactId>Jcef</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Jcef</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.10.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>22.0.1</version>
        </dependency>
        <!--<dependency>
            <groupId>org.jetbrains.intellij.deps.jcef</groupId>
            <artifactId>jcef</artifactId>
            <version>144.0.15-g72717cf-chromium-144.0.7559.172-api-1.21-262-b37</version>
        </dependency>-->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>22.0.1</version>
        </dependency>
        <dependency>
            <groupId>me.friwi</groupId>
            <artifactId>jcefmaven</artifactId>
            <version>146.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>22.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>22</source>
                    <target>22</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>group.jcef/group.jcef.HelloApplication</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

此外,这是 module-info.java

module group.jcef {
requires javafx.controls;
requires javafx.fxml;

    requires org.controlsfx.controls;
    requires javafx.swing;
    requires jcefmaven;
    requires jcef;

    opens group.jcef to javafx.fxml;
    exports group.jcef;
}

解决方案

这个模块是JetBrains Runtime的内部模块,其中包含JCEF(例如 jbrsdk_jcef),你必须在编译时显式告知构建系统将JDK的内部模块包含进来。

将此添加到你的 maven-compiler-plugin 配置中:

<compilerArgs>
    <arg>--add-modules=jcef</arg>
</compilerArgs>
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章