JavaFX 14 如何导出未导出的包?

JavaFX 14 how can I export a package that is not exported?

我正在处理 Netbeans 12 maven JavaFX 14.0.1 应用程序。

该应用程序类似于加载 css 个文件的主题查看器。

我想捕获 css 'StyleManager' 的警告(错误),这样我就可以像建议的那样警告用户

    StyleManager.errorsProperty().addListener((ListChangeListener<? super CssError>) c -> {
      while (c.next()) {
        for (CssError error : c.getAddedSubList()) {
          // maybe you want to check for specific errors here
          System.out.println(error.getMessage());
        }
      }
    });

问题是 com.sun.javafx.css.StyleManager 没有导出所以我得到错误:

(package com.sun.javafx.css is declared in module javafx.graphics, which does not export it to module com.johntor.app)

我试过添加

--add-exports javafx.graphics/com.sun.javafx.css=com.johntor.app

运气不好!

在此之前应用程序运行良好!!!

任何Ideas/Suggestions都非常欢迎

编辑:我包含了我的 pom 文件:

   <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.johntor</groupId>
       <artifactId>ThemeViewer3</artifactId>
       <version>1.0.0</version>
       <packaging>jar</packaging>
       <name>ThemeViewer3</name>
       <url>http://www.greek-developers.com</url>
       <properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <maven.compiler.source>14</maven.compiler.source>
           <maven.compiler.target>14</maven.compiler.target>
       </properties>
       <dependencies>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-controls</artifactId>
               <version>14.0.1</version>
           </dependency>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-fxml</artifactId>
               <version>14.0.1</version>
           </dependency>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-graphics</artifactId>
               <version>14.0.1</version>
           </dependency>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-web</artifactId>
               <version>14.0.1</version>
           </dependency>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-base</artifactId>
               <version>14.0.1</version>
           </dependency>
           <dependency>
               <groupId>org.openjfx</groupId>
               <artifactId>javafx-media</artifactId>
               <version>14.0.1</version>
           </dependency>
       </dependencies>
       <build>
           <plugins>
               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.8.1</version>
                   <configuration>
                       <release>14</release>
                       <mainClass>com.johntor.App</mainClass>
                       <compilerArgs>
                           <arg>--add-exports=javafx.graphics/com.sun.javafx.css=com.johntor.app</arg>
                       </compilerArgs>
                   </configuration>
               </plugin>
               <plugin>
                   <groupId>org.openjfx</groupId>
                   <artifactId>javafx-maven-plugin</artifactId>
                   <version>0.0.4</version>
                   <configuration>
                       <compilerArgs>
                           <arg>--add-exports</arg>
                           <arg>javafx.graphics/com.sun.javafx.css=com.johntor.app</arg>
                       </compilerArgs>
                       <mainClass>com.johntor.app.App</mainClass>
                       <options>
                           <option>--add-opens</option>
                           <option>javafx.controls/javafx.scene.control=com.johntor.app</option>
                           <option>--add-exports</option>
                           <option>javafx.graphics/com.sun.javafx.css=com.johntor.app</option>    
                           <option>--add-exports</option>
                           <option>javafx.graphics/com.sun.javafx.css=ALL-UNNAMED</option>                    
                       </options>
                   </configuration>
                   <executions>
                       <execution>
                           <id>default-cli</id>
                           <configuration>
                               <mainClass>com.johntor.app.App</mainClass>
                               <options>
                                   <option>--add-opens</option>
                                   <option>javafx.controls/javafx.scene.control=com.johntor.app</option>
                                   <option>--add-exports</option>
                                   <option>javafx.graphics/com.sun.javafx.css=com.johntor.app</option> 
                               </options>
                               <stripDebug>true</stripDebug>
                               <compress>2</compress>
                               <noHeaderFiles>true</noHeaderFiles>
                               <noManPages>true</noManPages>
                               <launcher>${project.artifactId}</launcher>
                               <jlinkImageName>../Deploy</jlinkImageName>
                               <!--<jlinkZipName>${project.artifactId}</jlinkZipName>-->
                           </configuration>
                       </execution>
                       <execution>
                           <id>debug</id>
                           <configuration>
                               <options>
                                   <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                               </options>
                           </configuration>
                       </execution>
                       <execution>
                           <id>ide-debug</id>
                           <configuration>
                               <options>
                                   <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                               </options>
                           </configuration>
                       </execution>
                       <execution>
                           <!--Configuration for automatic IDE profiling-->
                           <id>ide-profile</id>
                           <configuration>
                               <options>
                                   <option>${profiler.jvmargs.arg1}</option>
                                   <option>${profiler.jvmargs.arg2}</option>
                                   <option>${profiler.jvmargs.arg3}</option>
                                   <option>${profiler.jvmargs.arg4}</option>
                                   <option>${profiler.jvmargs.arg5}</option>
                               </options>
                           </configuration>
                       </execution>
                   </executions>
               </plugin>
           </plugins>
                   <resources>
               <resource>
                   <directory>src/main/java</directory>
                   <includes>
                       <include>**/*.fxml</include>
                       <include>**/*.css</include>
                       <include>**/*.properties</include>
                   </includes>
               </resource>
               <resource>
                   <directory>src/main/resources</directory>
                   <includes>
                       <include>**/*.xml</include>
                       <include>**/*.png</include>
                       <include>**/*.css</include>
                       <include>**/*.properties</include>
                   </includes>
               </resource>
               <resource>
                   <directory>.</directory>
                   <includes>
                       <include>readme.txt</include>
                   </includes>
               </resource>
           </resources>
       </build>
   </project>

提前谢谢你,

J!

这是我的 pom,适用于一个非常简单的 javafx maven 项目。

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <groupId>org.example</groupId>
    <artifactId>MavenFxied</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>14.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>11</release>
                    <compilerArgs>
                        <arg>--add-exports=javafx.graphics/com.sun.javafx.css=mavenfxied</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>example.Main</mainClass>
                    <options>
                        <option>--add-exports</option>
                        <option>javafx.graphics/com.sun.javafx.css=mavenfxied</option>
                        <option>--add-opens</option>
                        <option>javafx.graphics/com.sun.javafx.css=mavenfxied</option>
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我能够使用 mvn package 和 运行 构建项目 mvn javafx:run

我的模块名为 'mavenfxied',我的包名为 'example'。

这是有效的最终 pom。我把它包括在内是为了拯救别人。

我有一个不好的印象,即 --add-exports 允许在编译和 运行 时间导出,因此比 --add-opens 提供更大的自由度。但是 --add-opens 启用了深度反射,所以这里必须使用它。

        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.4</version>
            <configuration>
                <mainClass>com.johntor.app.App</mainClass>
                <options>
                    <option>--add-opens</option>
                    <option>javafx.controls/javafx.scene.control=com.johntor.app</option>
                    <option>--add-opens</option>
                    <option>javafx.graphics/com.sun.javafx.css=com.johntor.app</option>                    
                </options>
            </configuration>
            .
            .
            .

感谢matt