如果您希望类路径上的JavaFX模块,那么创建一个不扩展的单独的主类
Application
并调用
Application.launch(YourApp.class, args)
main
方法。
cfrick的例子是简化的Gradle项目
here
. 我添加了以下行:
installDist{}
... 这将使新任务可用:
./gradlew installdist
然后将在build/install/下生成一个可执行文件。
万一cfrick的github页面消失了,build.gradle 是这样的:
plugins {
id 'groovy'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
jcenter()
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls' ]
}
dependencies {
implementation 'org.codehaus.groovy:groovy:3.+'
}
application {
mainClassName = 'ofx.App'
}
installDist{} // my addition
和src/main/groovy/ofx/App.groovy 是这样的:
package ofx
import javafx.application.Application
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.StackPane
import javafx.stage.Stage
class App {
static void main(String[] args) {
Application.launch(HelloFx, args)
}
}
class HelloFx extends Application {
@Override
void start(Stage stage) {
def javaVersion = System.getProperty("java.version")
def javafxVersion = System.getProperty("javafx.version")
Label l = new Label("Hello, JavaFX $javafxVersion, running on Java $javaVersion.")
Scene scene = new Scene(new StackPane(l), 640, 480)
stage.setScene(scene)
stage.show()
}
}