我正在使用Gradle构建一个jar。我使用Intellij和Java 1.8,当我在Intellij环境中运行它时,一切似乎都没问题,但是当我想启动jar时,我得到以下错误:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/BehaviorSkinBase
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.controlsfx.control.PropertySheet.createDefaultSkin(PropertySheet.java:254)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Unknown Source)
at javafx.controls/javafx.scene.control.Control.access$000(Unknown Source)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.scene.control.skin.BehaviorSkinBase
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 67 more
Exception running application de.informatik.gitlab2.itv.Main
有两个外部依赖项(controlsfx和jdom2),它们通过gradle构建文件中的maven包含。
这是使用以下内容的build.gradle文件:
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
libs
}
dependencies{
testCompile group: 'junit', name: 'junit', version: '4.12
// https://mvnrepository.com/artifact/org.jdom/jdom
libs group: 'org.jdom', name: 'jdom', version: '2.0.0'
// https://mvnrepository.com/artifact/org.controlsfx/controlsfx
libs group: 'org.controlsfx', name: 'controlsfx', version: '8.40.14'
configuration.compile.extendsFrom(configurations.libs)
}
jar {
manifest {
attributes 'Main-Class': 'de.informatik.gitlab2.itv.Main'
}
from {
configurations.libs.collect { it.isDirectory() ? it : zipTree(it) }
}
}
修改
添加
后compile group: 'net.java.openjfx.backport', name: 'openjfx-78-backport-compat', version: '1.8.0.1'
进入build.gradle,发生此错误:
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)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Unknown Source)
at javafx.controls/javafx.scene.control.Control.access$000(Unknown Source)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Unknown Source)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Node.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Node.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Node.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Node.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Scene.doCSSPass(Unknown Source)
at javafx.graphics/javafx.scene.Scene.access$3500(Unknown Source)
at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/BehaviorSkinBase
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.controlsfx.control.PropertySheet.createDefaultSkin(PropertySheet.java:254)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Unknown Source)
at javafx.controls/javafx.scene.control.Control.access$000(Unknown Source)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Unknown Source)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.doProcessCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.access$400(Unknown Source)
at javafx.graphics/javafx.scene.Parent$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.doProcessCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.access$400(Unknown Source)
at javafx.graphics/javafx.scene.Parent$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(Unknown Source)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.superProcessCSSImpl(Unknown Source)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.superProcessCSS(Unknown Source)
at javafx.controls/javafx.scene.control.Control.doProcessCSS(Unknown Source)
at javafx.controls/javafx.scene.control.Control.access$000(Unknown Source)
at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Unknown Source)
at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.doProcessCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.access$400(Unknown Source)
at javafx.graphics/javafx.scene.Parent$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.doProcessCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.access$400(Unknown Source)
at javafx.graphics/javafx.scene.Parent$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.doProcessCSS(Unknown Source)
at javafx.graphics/javafx.scene.Parent.access$400(Unknown Source)
at javafx.graphics/javafx.scene.Parent$1.doProcessCSS(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.processCSSImpl(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Node.processCSS(Unknown Source)
at javafx.graphics/javafx.scene.Scene.doCSSPass(Unknown Source)
at javafx.graphics/javafx.scene.Scene.preferredSize(Unknown Source)
at javafx.graphics/javafx.scene.Scene$2.preferredSize(Unknown Source)
at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(Unknown Source)
at javafx.graphics/javafx.stage.Window$12.invalidated(Unknown Source)
at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source)
at javafx.base/javafx.beans.property.BooleanPropertyBase.set(Unknown Source)
at javafx.graphics/javafx.stage.Window.setShowing(Unknown Source)
at javafx.graphics/javafx.stage.Window.show(Unknown Source)
at javafx.graphics/javafx.stage.Stage.show(Unknown Source)
at de.uniwuerzburg.informatik.gitlab2.itv.Main.start(Main.java:35)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.scene.control.skin.BehaviorSkinBase
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 67 more
Exception running application de.informatik.gitlab2.itv.Main
EDIT2 我编辑了build.gradle文件:
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) } }
}
在进行干净的Gradle构建之后,这是MANIFEST.MF的代码
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.informatik.gitlab2.itv.Main
以下是jar的结构:
...
css
de
fxml
impl
java
javax
lang
META-INF
netscape
nodes
org
sun
controlsfx.properites
我的两个依赖项位于文件夹' org'中。不应该在清单中使用org / ...的类路径?如果不同的依赖关系之间的MANIFEST.MF中没有空格,如果我如何解决它,这是一个错误吗?
从cmd运行时的异常与上面相同:
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)
答案 0 :(得分:0)
com.sun.javafx.scene.control.skin.BehaviorSkinBase类属于
JavaFX 78 Backport兼容性库»1.8.0.1
请在build.gradle文件中添加以下gradle依赖项:
编译组:'net.java.openjfx.backport',名称:'openjfx-78-backport-compat',版本:'1.8.0.1' < / p>
参考:https://mvnrepository.com/artifact/net.java.openjfx.backport/openjfx-78-backport-compat/1.8.0.1
答案 1 :(得分:0)
可能是因为多个jdk或当前的jdk不支持皮肤(controlfx)... 设置对我有用(Java 8,Javafx 8),你可以查看类似的openjfx - 转到文件&gt;项目结构&gt;
项目
库