1

Java fx を使用した Java 8 プロジェクトがあります。最近、Java11 と OpenJFX11 に切り替えました。

gradle run または JVM 引数を使用すると、すべてが正常に実行されます。しかし、jar をビルドするとすぐに、実行可能な jar は次のエラーのために実行されません。

エラー: メイン クラス sample.application.main.SampleAppLauncher が見つからないか読み込めませんでした

原因: java.lang.NoClassDefFoundError: javafx/application/Application

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()

    }
}

plugins {
    id 'java'
    id 'java-library'
    id 'maven-publish'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

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

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    archiveClassifier.set("sources")
}
task javadocJar(type: Jar, dependsOn: javadoc) {
     archiveClassifier.set("javadoc")
    from javadoc.destinationDir
}


mainClassName="sample.application.main.Launcher"

publishing {
     publications {
            mavenAar(MavenPublication) {
                from components.java
                afterEvaluate {
                    artifact javadocJar
                    artifact sourcesJar
                }
            }
        }
    }
    
javafx {
    version = "11"
    modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics']
}


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


dependencies {
    
    api 'org.apache.commons:commons-math3:3.6.1'

   
    implementation 'com.google.guava:guava:27.0.1-jre'
    
    
    testImplementation 'junit:junit:4.12'
    implementation 'org.openjfx:javafx:11'
    compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
    compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
    compile group: 'org.openjfx', name: 'javafx', version: '11'
    
    
    
}

jar {
  manifest {
    attributes(
      'Main-Class': 'sample.application.main.Launcher'
    )
    
  }
  from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

通常の Jar Build 用にさらに何かを定義する必要がありますか? 私が今知っている唯一の方法は、 openjfx-11 へのパスを指定して JVM 引数を指定してアプリケーションを実行することです。ただし、これは JavaFX11 を持たない他のシステムでは機能しません。

他のすべての依存関係と同様に、gradle によって jar にコンパイルされると思いました。

JFX11について何か違いはありますか?

編集:

アプリケーション クラス:


public class SampleAppLauncher extends Application {


    @Override
    public void start(Stage stage) throws Exception {
        \\... startup
        

    }

}

ランチャー:

public class Launcher {
    public static void main(String[] args) {
        SampleAppLauncher.launch(args);
    }
}

モジュール情報

module FXproject {
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;
    
    opens sample.application.main to javafx.fxml;
    exports sample.application.main;
}

4

0 に答える 0