如何用module-info.java文件替换VM参数

时间:2019-12-06 13:39:46

标签: java eclipse javafx runtime-error jvm-arguments

我刚刚开始了一个基于h = model.fit(x=dtgen.next_train_batch(), epochs=epochs, steps_per_epoch=dtgen.steps['train'], validation_data=dtgen.next_valid_batch(), validation_steps=dtgen.steps['valid'], callbacks=callbacks, shuffle=True, verbose=1) AdoptOpenJDK 11的新项目。

在开发之前,我使用过VM Arguments,当您将项目传递给其他人时,这并不总是可行的。

所以我开始用OpenJavaFX 11文件替换我的VM参数。

之前的虚拟机参数:

module-info.java
现在

--module-path ${PATH_TO_FX} –add-modules javafx.controls,javafx.fxml --add-opens javafx.base/com.sun.javafx.runtime=ALL-UNNAMED --add-opens javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED --add-opens javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED --add-opens javafx.base/com.sun.javafx.binding=ALL-UNNAMED --add-opens javafx.base/com.sun.javafx.event=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED --add-opens javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED 个文件:

module-info.java

这是我遇到的问题,我设法替换了标签module hellofx { requires javafx.controls; requires javafx.fxml; requires transitive javafx.graphics; opens org.openjfx to javafx.fxml; exports org.openjfx; } ,但找不到标签--module path的解决方案。

有人可以帮我吗?

编辑12/09:

现在我在--add-open

的这两行中遇到新的错误

module-info.java

我该如何解决?

1 个答案:

答案 0 :(得分:1)

选项A快速干净:

更改


module hellofx {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;

//wrong
opens org.openjfx to javafx.fxml;

//right
opens com.your.package to javafx.fxml, javafx.controls;

exports org.openjfx;

}

选项B(因为用javaFX构建Jar似乎很奇怪)

您还可以使用Gradle进行此操作(因为这样您就可以轻松构建JavaFX jar,而不会出现很多问题)

您应该添加gradle fx插件,并定义Compile参数。

使用Gradle时,您也不需要手动下载openJavaFX库。

这是您的Gradle文件的外观




buildscript {
    dependencies {
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.7.0'
        classpath 'org.openjfx:javafx:11'

    }
    repositories {
        mavenLocal()
        mavenCentral()
         maven {
            url "https://plugins.gradle.org/m2/"
        }

    }
}

plugins {
    id 'eclipse'
    id 'java'
    id 'java-library'
    id 'application'
    // This is very Important!
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.jlink' version '2.12.0'
}

sourceCompatibility = 11
targetCompatibility = 11
repositories {
    jcenter()
    mavenCentral()
}



mainClassName="com.your.MainLauncher"



// Use this for the Runtime, to run with the required Modules

javafx {
    version = "11"
    modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics']
}


sourceSets {
    main.java.srcDir "src/main/java"
    main.resources.srcDir "src/main/resources"
}

// Your dependecies
dependencies {

    compile group: 'org.openjfx', name: 'javafx', version: '11.0.2'
    // JAVA FX dependecy. Important!
    // Add your other dependecies


}

// to build the jar
jar {
  manifest {
    attributes(
      'Main-Class': 'com.your.MainLauncher'
    )

  }
  from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

// to "include compile arguments " that replace your VM arguments
compileJava {
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
        ]
        println options.compilerArgs
    }

}


您可以使用gradle来运行它,也可以使用Eclipse来运行它。 生成jar时,也不需要VM参数。希望对您有帮助。

如果您安装了Gradle Support插件,这也将耗尽您的IDE(intelliJ / Eclipse)。