英文:
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<? 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());
}
}
});
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:
<?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>
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.
<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>
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.
<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>
.
.
.
Thanks to matt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论