Creating jar from javaFX gradle project

Answered

New to Gradle, and trying to make a executable jar so I can run my project on a raspberry PI. It builds and runs succesfully, and after building jar with the gradle panel on the right in intellij, I try to run it with

java -jar .\build\libs\<name of jar file>

It then gets an error: 
Error: Could not find or load main class org.openjfx.MainApp
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

My build.gradle file:

plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}

jar {
manifest {
attributes 'Main-Class': 'org.openjfx.MainApp'
}
}

repositories {
mavenCentral()
jcenter()
}

dependencies {
compile 'org.kordamp.ikonli:ikonli-javafx:11.3.4'
compile 'org.kordamp.ikonli:ikonli-weathericons-pack:11.3.4'
compile group: 'org.dom4j', name: 'dom4j', version: '2.1.0'
compile 'joda-time:joda-time:2.10.3'
compile 'com.google.api-client:google-api-client:1.23.0' // Google cal
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0' // Google cal
compile 'com.google.apis:google-api-services-calendar:v3-rev305-1.23.0' // Google cal
}

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



mainClassName = 'org.openjfx.MainApp'
sourceCompatibility = 1.8 // Google cal
targetCompatibility = 1.8 // Google cal
version = '1.0' // Google cal

 

Started out with this simple guide: https://openjfx.io/openjfx-docs/
This was a simple JavaFX and IntelliJ with Gradle project, and then added some dependencies, and classes. 
Runs ok, but  when I stop I also get this fail:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\Java\jdk-12.0.2\bin\java.exe'' finished with non-zero exit value 1

Maybe it has something to do with that, but don't understand the whole gradle process yet.

Appreciate all the help I can get

 

0
5 comments

Hello,

Could you please share sample project for investigation?

0

Here is my project structure:


But noticed an error in my MANIFEST.MF, where it 'cannot resolve the class MainApp'. Not sure how to fix this, the code looks like this:

Manifest-Version: 1.0
Main-Class: org.openjfx.MainApp




0

Have you tried to run "File | Invalidate Caches" and reimporting project from Gradle tool window?

Is it possible to attach exact project for investigation? Probably there is something wrong with configuration.

0

Please check this part of documentation: https://openjfx.io/openjfx-docs/#install-java

In order to create a runnable jar with all the required JavaFX dependencies, you will need to use a launcher class that doesn't extend from Application.

0

Please sign in to leave a comment.