0

我必须将我的项目从 SWT 转换为 JavaFX。该项目充分利用 luaj 来强制和执行 lua 脚本,并且在 swt 中运行良好。

但与 javafx 有区别。Javafx 作为一个模块工作。

从那以后,我就遇到了luaj的麻烦。

尝试了两种不同的方法:

** 在类路径中使用 luaj **

Eclipse 不再看到它(类型 org.luaj.vm2.[...] 不可访问)。尝试使用订单但仍然无法正常工作。

使用 luaj 作为自动命名模块

我尝试作为用户库或直接作为外部 jar。

在这种情况下,eclipse 会看到 luaj 包。但是当我跑步时,我有消息

启动层初始化时出错

java.lang.module.FindException:无法为 E:\eclipse-workspace\Lib\luaj-3.0.1\lib\luaj-jse-3.0.1.jar 派生模块描述符 原因:java.lang.module.InvalidModuleDescriptorException :在顶级目录中找到 luajc.class(模块中不允许使用未命名的包)

我认为 lib 文件的名称很糟糕。我有一条警告说“自动模块 luaj.jse 的名称不稳定”,但是当我尝试重命名它时,当 eclipse 搜索旧文件名时出现错误。

这可以是原因吗?

我使用 jdk-16

这里是我的模块信息...

module dusandbox {
    requires javafx.graphics;
    requires javafx.controls;
    requires javafx.base;
    requires javafx.fxml;
    requires javafx.media;
    requires javafx.swing;
    requires javafx.swt;
    requires javafx.web;
    requires java.xml;
    requires luaj.jse;
    
    exports dusandbox;
    exports dusandbox.setup;
    exports dusandbox.obj;
    opens dusandbox.setup to javafx.fxml;
    opens dusandbox.obj to javafx.fxml;
}

虚拟机参数

--module-path "E:\eclipse-workspace\Lib\javafx-sdk-11.0.2\lib"
--add-opens javafx.graphics/com.sun.javafx.text=ALL-UNNAMED

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="lib" path="E:/eclipse-workspace/Lib/luaj-3.0.1/lib/luaj-jse-3.0.1.jar">
        <attributes>
            <attribute name="module" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="fxml/|picture/|pictures/" kind="src" path="src">
        <attributes>
            <attribute name="module" value="true"/>
            <attribute name="add-exports" value="dusandbox/dusandbox.setup=dusandbox"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFx">
        <attributes>
            <attribute name="module" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
        <attributes>
            <attribute name="module" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="E:/eclipse-workspace/Lib/javax.xml.bind.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

感谢您的帮助!我从 2 天开始就在搜索,我很困惑!

编辑似乎 luaj 不能作为模块工作。我仍然坚持让它在类路径中工作......

4

1 回答 1

1

解决了

我删除了模块信息并在模块路径中添加了所有 javafx 库。

我将VM参数替换为

--module-path "E:\eclipse-workspace\Lib\javafx-sdk-11.0.2\lib"
--add-modules javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.web

Notice that you have to select which javafx modules you want to use in the add-modules argument.

于 2021-07-17T13:20:48.987 回答