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

huangapple go评论78阅读模式
英文:

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()) {
      // 可能你想在这里检查特定的错误
      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

但没有任何运气!

在此之前,应用程序运行正常!

非常感谢您的建议和想法。

编辑:我包含了我的 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">
   <!-- ... POM 配置 ... -->
</project>

提前致谢,

J!

英文:

I'm working on Netbeans 12 maven JavaFX 14.0.1 application.

The application is something like a theme viewer loading css files.

I want to capture Warnings (Errors) of the css 'StyleManager' so I can warn the user as it was proposed on this solution

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

The problem is that com.sun.javafx.css.StyleManager is not exported so I get the error:

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

I tried adding

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

without any luck!

Before this the application was working fine!!!

Any Ideas/Suggestions are more than welcome

EDIT: I included my pom file:

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

Thank you in advance,

J!

答案1

得分: 0

这是适用于非常简单的JavaFX Maven项目的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>
    <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

英文:

Here is my pom that works for a very simple javafx maven project.

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;properties&gt;
&lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
&lt;/properties&gt;
&lt;groupId&gt;org.example&lt;/groupId&gt;
&lt;artifactId&gt;MavenFxied&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-controls&lt;/artifactId&gt;
&lt;version&gt;14.0.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
&lt;version&gt;14.0.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.1&lt;/version&gt;
&lt;configuration&gt;
&lt;release&gt;11&lt;/release&gt;
&lt;compilerArgs&gt;
&lt;arg&gt;--add-exports=javafx.graphics/com.sun.javafx.css=mavenfxied&lt;/arg&gt;
&lt;/compilerArgs&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.openjfx&lt;/groupId&gt;
&lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.0.4&lt;/version&gt;
&lt;configuration&gt;
&lt;mainClass&gt;example.Main&lt;/mainClass&gt;
&lt;options&gt;
&lt;option&gt;--add-exports&lt;/option&gt;
&lt;option&gt;javafx.graphics/com.sun.javafx.css=mavenfxied&lt;/option&gt;
&lt;option&gt;--add-opens&lt;/option&gt;
&lt;option&gt;javafx.graphics/com.sun.javafx.css=mavenfxied&lt;/option&gt;
&lt;/options&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

I was able to build with mvn package and run the project with mvn javafx:run.

My module is named 'mavenfxied' and my package is 'example'.

答案2

得分: 0

以下是已经翻译好的内容:

这是最终可用的 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>
    .
    .
    .
</plugin>

感谢 matt

英文:

Here is the final pom that worked. And I include it to save somebody else.

I had a bad impression that --add-exports enables exporting on both compile and run time so gives greater freedom than --add-opens. But --add-opens enables deep reflection so it must be used here.

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

Thanks to matt

huangapple
  • 本文由 发表于 2020年7月23日 23:02:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63057304.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定