Building incorrect jar file with gradle.build

Im trying to build a jar file of my java 1.8 code using intellij. If im running the code in intelliy everything is ok, but when i build a gradle which doesnt produce any errors and try to start the jar in the cmd
i get the following error:

Exception in Application start method
Exception in thread “JavaFX Application Thread” java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/BehaviorSkinBase
at org.controlsfx.control.PropertySheet.createDefaultSkin(PropertySheet.java:254)

Here is my build.gradle file :

version ‘1.0-SNAPSHOT’

apply plugin: ‘java’
apply plugin: ‘idea’
//apply plugin: ‘application’

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()

}

dependencies {

//
// https://mvnrepository.com/artifact/org.jdom/jdom
compile (
[group: ‘org.jdom’, name: ‘jdom’, version: ‘2.0.0’],
[group: ‘org.controlsfx’, name: ‘controlsfx’, version: ‘8.40.14’],
[group: ‘net.java.openjfx.backport’, name: ‘openjfx-78-backport-compat’, version: ‘1.8.0.1’]
)
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.12’
}

//mainClassName = ‘de.informatik.gitlab2.itv.Main’

jar {
manifest {
attributes( ‘Main-Class’: ‘de.informatik.gitlab2.itv.Main’,
‘Class-Path’ : configurations.compile.collect{ it.getName() }.join(‘’))
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

This gradle.build produces a MANIFEST.MF with:

Manifest-Version: 1.0
Class-Path: jdom-2.0.0.jarcontrolsfx-8.40.14.jaropenjfx-78-backport-co
mpat-1.8.0.1.jar
Main-Class: de.uniwuerzburg.informatik.gitlab2.itv.Main

And the file structure of my jar after the build is :


css
de
fxml
impl
java
javax
lang
META-INF
netscape
nodes
org
sun

In the folder org are the two dependencies ControlsFX and JDOM

It looks like Its not getting the Class file(BehaviorSkinBase) at runtime which was present in compile time

My assumption is that there is something wrong with the ClassPath in the Manifest file. Is is normal that there are noch whitespaces between two different dependencies and why ist there no directory org/jdom in the classpath? If this is the Problem how can i solve it?

No, there should be spaces. It looks like your version is joining with an empty string ('') instead of a space (' ').

"Class-Path": configurations.compile.collect { it.getName() }.join(' '))

However, this shouldn’t matter at all. You’re copying the contents of your dependency JARs into your application JAR (building a fat JAR). The manifest doesn’t need to call out the names of the JARs that the classes came from if you’re already copying those classes into your application JAR. They’re already on the classpath by being in the JAR you’re running.

What JRE are you using? The JavaFX runtime is bundled in the Oracle JRE, but that is not normally the case for other vendor builds. As the failure is in a class from the controlsfx dependency, that JAR was likely compiled with the Oracle JDK, but you’re running with an OpenJDK build or similar that doesn’t include the JavaFX runtime by default.

Im using jre1.8.0_152 from www.oracle.com

Does jfxrt.jar exist in the /path-to-your-jdk/jre/lib/ext directory? This is the JavaFX runtime JAR that contains the not found BehaviorSkinBase class. It should be in that directory to automatically be added to the classpath.

Yes jfxrt.jar exist in my jre/lib/ext directory. And in this jar also is the jfxrt.jar\com\sun\javafx\scene\control\skin\BehaviorSkinBase