1

I build my project using gradle jar command, then try to start my application using command java -jar MyProject.jar

After that I have error:

Error: Could not find or load main class org.apdalgo.Main<br>
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

My build.gardle:

    plugins {
        id 'java'
        id 'application'
        id 'org.openjfx.javafxplugin' version '0.0.7'
    }
    
    group 'org.apdalgo'
    version '1.0-SNAPSHOT'
    
    sourceCompatibility = 11
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.12'
    }
    
    javafx {
        version = "12"
        modules = [ 'javafx.controls', 'javafx.fxml' ]
    }
    
    mainClassName = 'org.apdalgo.Main'
    
    jar {
        manifest {
            attributes 'Main-Class': 'org.apdalgo.Main',
                    'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
        }
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    }
jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
  • Does this answer your question? [JavaFX 11 : Create a jar file with Gradle](https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle) – Andrey Jun 28 '20 at 08:58

1 Answers1

1

The command line need a bit more see https://openjfx.io/openjfx-docs/#install-javafx

java --module-path <PATH_TO_FX> --add-modules javafx.controls

PrasadU
  • 2,154
  • 1
  • 9
  • 10