Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Maven和jlink的OpenJFX自定义运行时映像-模块导出或命令行参数?_Java_Javafx_Javafx 11_Openjfx - Fatal编程技术网

Java 使用Maven和jlink的OpenJFX自定义运行时映像-模块导出或命令行参数?

Java 使用Maven和jlink的OpenJFX自定义运行时映像-模块导出或命令行参数?,java,javafx,javafx-11,openjfx,Java,Javafx,Javafx 11,Openjfx,我正在尝试创建一个自定义运行时映像,它不需要在计算机上安装JRE/JDK。我已经遵循了OpenJFX文档(JavaFX和IntelliJ-Modular with Maven)上提供的教程,我能够运行创建的映像,但我希望在我的应用程序类com.sun.glass.ui.Window(在模块JavaFX.graphics中)中包含它 在自定义图像之前,我将以下内容作为命令行参数进行解析: --添加打开javafx.graphics/com.sun.glass.ui=ALL-UNNAMED 我想在运

我正在尝试创建一个自定义运行时映像,它不需要在计算机上安装JRE/JDK。我已经遵循了OpenJFX文档(JavaFX和IntelliJ-Modular with Maven)上提供的教程,我能够运行创建的映像,但我希望在我的应用程序类com.sun.glass.ui.Window(在模块JavaFX.graphics中)中包含它

在自定义图像之前,我将以下内容作为命令行参数进行解析: --添加打开javafx.graphics/com.sun.glass.ui=ALL-UNNAMED

我想在运行时包含它,所以我应该修改Maven的pom以包含javafx Maven插件a(未成功),还是编辑project module.info以从javafx.graphics导出请求的包

谢谢, 安德烈

Pom.xml module.info.java

module com.andrei {
    requires javafx.controls;
    requires javafx.graphics;
    exports com.andrei;
    exports com.sun.glass.ui to com.andrei;
}

“Package”com.sun.glass.ui”在模块“javafx.graphics”中声明,该模块不会导出到模块“com.andrei”

javafx maven插件应该能够执行您尝试执行的操作。然而,到目前为止,它还没有做到这一点,所以我刚刚提交了这两个问题:和

在解决此问题并发布新版本的同时,还有一个简单(但手动)的修复:

编译时间

在修改
javafxmaven插件之前,您需要允许您的IDE使用私有包。您不能从模块信息中执行此操作,但可以使用
compilerArgs
maven编译器插件
轻松执行此操作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <compilerArgs>
            <arg>--add-exports</arg>
            <arg>javafx.graphics/com.sun.glass.ui=com.andrei</arg>
        </compilerArgs>
    </configuration>
</plugin>
运行时

但是,如果执行
mvn clean compile javafx:run
,上述代码将失败:

原因:java.lang.IllegalAccessError:class com.andrei.Main(在模块com.andrei中)无法访问class com.sun.glass.ui.Window(在模块javafx.graphics中),因为模块javafx.graphics没有将com.sun.glass.ui导出到模块com.andrei

如插件中所述,您可以添加将传递到
java
工具的VM选项:

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.2</version>
    <configuration>
        <options>
            <option>--add-opens</option>
            <option>javafx.graphics/com.sun.glass.ui=com.andrei</option>
        </options>
        ...
</configuration>
</plugin>
现在,
mvn clean compile javafx:jlink
可以工作了,但是运行时会出现与上面相同的错误,因为没有导出私有包

但是,您可以在
目标/image/bin/launcher
下编辑启动器文件:

#!/bin/sh
JLINK_VM_OPTIONS=
DIR=`dirname $0`
$DIR/java $JLINK_VM_OPTIONS -m com.andrei/com.andrei.Main $@
如您所见,有一个空的
JLINK\u VM\u OPTIONS
变量可以用您的VM选项填充

在第二个问题解决之前,只需修改该行:

#!/bin/sh
JLINK_VM_OPTIONS="--add-opens javafx.graphics/com.sun.glass.ui=com.andrei"
DIR=`dirname $0`
$DIR/java $JLINK_VM_OPTIONS -m fx/org.openjfx.MainApp $@

保存并运行:
target/image/bin/launcher
,它就会工作。

我将跟踪您在GitHub上的请求状态,以获取有关此主题的进一步更新。再次感谢你@AndreiD我刚刚提交了一份公关文件,应该可以解决这两个问题。如果您想提前测试,请使用
mvn clean install
克隆并安装插件,然后在您的项目中使用
0.0.3-SNAPSHOT
。欢迎您的反馈。我已尝试克隆,但我得到:org.openjfx:javafx maven plugin:jar:0.0.3-SNAPSHOT缺少POM,没有可用的依赖信息。另外,我还有一个问题。是否可以附加远程调试器?使用-agentlib进行调试,请参见。
#!/bin/sh
JLINK_VM_OPTIONS=
DIR=`dirname $0`
$DIR/java $JLINK_VM_OPTIONS -m com.andrei/com.andrei.Main $@
#!/bin/sh
JLINK_VM_OPTIONS="--add-opens javafx.graphics/com.sun.glass.ui=com.andrei"
DIR=`dirname $0`
$DIR/java $JLINK_VM_OPTIONS -m fx/org.openjfx.MainApp $@