gpt4 book ai didi

java - 使用 Java 9+ 模块设置在 CLI 中运行 Groovy

转载 作者:行者123 更新时间:2023-12-01 17:56:20 26 4
gpt4 key购买 nike

操作系统:Linux Mint 18.3我想要运行的组合是:Groovy 3.0.+(应用程序和测试代码)& Java 11+ & JavaFX 11+

有了一点帮助(请参阅评论 here ),我现在可以使用 gradle.build 文件来执行此操作(包括使用 application 插件中的 Gradle“installDist”任务输出可执行文件) .

我还通过适当配置类路径和模块路径,在 IntelliJ 中的非 Gradle Groovy 启用项目中成功做到了这一点。

我的文件 javaFXTest.groovy 看起来像这样(注意,这是我让 IntelliJ 运行的 Groovy 脚本):

package core

import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage

Application.launch( GrApp, args)

class GrApp extends Application {

@Override
void start(Stage primaryStage) {
Parent root = FXMLLoader.load(getClass().getResource("/dialog1.fxml"))
primaryStage.title = "Hello World"
primaryStage.scene = new Scene(root, 1200, 800)
primaryStage.show()
}
}

出于兴趣,我只是想知道这实际上是如何通过 CLI groovy 命令完成的。我想可能是这样的:

groovy -cp .:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/*  --module-path /home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml core/javaFXTest.groovy 

哎呀:

Caught: java.io.FileNotFoundException: /home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path (/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path)

...它显然无法将 --module-path 识别为可配置选项,通过 groovy --help 确认。我对此进行了搜索,但一无所获。然而 IntelliJ 设法运行此脚本:--module-path--add-modules 选项作为 VM 选项添加到运行配置中。有人知道如何通过 CLI 命令来完成此操作吗?

最佳答案

根据 cfrick 的建议,我找到了答案:Intellij 确实在“运行” View 中显示整个命令(如果您单击“...”):

事实证明这是一个巨大的 Java 命令,其中包含超出我理解的各种内容,例如包含许多 Groovy .jar。我向感兴趣的人展示了它的宏伟:我将其分成几行以更清楚地显示选项。

/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java 
-Dgroovy.home=/home/mike/.sdkman/candidates/groovy/3.0.2
-Dgroovy.starter.conf=/home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
-javaagent:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/lib/idea_rt.jar=41350:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/bin
-Dfile.encoding=UTF-8
-classpath /home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar org.codehaus.groovy.tools.GroovyStarter
--conf /home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
--main groovy.ui.GroovyMain
--classpath .:/home/mike/IdeaProjects/JavaFXExp2/out/production/AppTest:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-yaml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-launcher-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-api-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-engine-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-templates-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovysh-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsp-api-2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-dataformat-yaml-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javaparser-core-3.15.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-json-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-launcher-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-xml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-testng-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jmx-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-logging-1.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-dateutil-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-4.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/hamcrest-core-1.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/xstream-1.4.11.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ivy-2.5.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-servlet-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/gpars-1.2.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jcommander-1.72.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsr166y-1.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-antlr-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/multiverse-core-0.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jsr223-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-sql-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovydoc-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/bsf-2.4.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/org.abego.treelayout.core-1.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-core-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ST4-4.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-console-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-annotations-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jansi-1.18.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-datetime-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-astbuilder-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jaxb-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-ant-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-junit5-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-swing-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/qdox-1.12.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-picocli-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javax.servlet-api-3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-commons-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-macro-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-nio-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-engine-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-commons-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/testng-6.14.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-databind-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-junit-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/opentest4j-1.2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-bsf-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-cli-1.4.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/snakeyaml-1.24.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jline-2.14.6.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-docgenerator-3.0.2.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/src.zip:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx-swt.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.web.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.media.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.swing.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.controls.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.graphics.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-api-2.3.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/activation-1.1.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-core-2.3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-impl-2.3.0.1.jar

--encoding=UTF-8
/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/core/javaFXTest.groovy

我猜测第一个 -classpath 选项(带有单破折号)可能是为“javaagent”设置的...或者可能是为“Groovy starter”设置的。 .?

这至少解决了这个难题:我知道 Groovy(甚至 Groovy 3)无法处理 Java 9+ 模块。因此,这肯定是一个 Java 命令,这是有道理的。也许使用 Groovy 4 可以使用 groovy 命令运行,据我了解,它(希望)能够处理这些模块。

关于java - 使用 Java 9+ 模块设置在 CLI 中运行 Groovy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60710234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com