如何解决SpringBoot一个JavaFx项目在Ide上运行,当我运行Jar文件时,出现错误:ClassNotFoundException
我用Springboot和JavaFx编写了一个小项目(jdk 8)来制作简单的UI。 当我在IDE(STS,Eclipse,Intellij)上运行时,一切正常。
当我打包到Jar文件时,我运行它(从Windows 10)或在提示符cmd上运行,它不起作用,并且出现此问题:
Exception in thread "main" java.lang.reflect.InvocationTargetException...
..Caused by: java.lang.classNotFoundException: **com.sun.javafx.scene.control.skin.BehaviorSkinBase**
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__,| / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.8.RELEASE)
2020-08-30 18:37:50.037 INFO 16216 --- [JavaFX-Launcher] o.s.boot.SpringApplication : Starting application on LAPTOP-C0C6FJ96 with PID 16216 (C:\Users\user\Documents\workspace-spring-tool-suite-4-4.5.1.RELEASE\Export-FX\target\Export-FX-0.0.1-SNAPSHOT.jar started by user in C:\Users\user)
2020-08-30 18:37:50.042 INFO 16216 --- [JavaFX-Launcher] o.s.boot.SpringApplication : No active profile set,falling back to default profiles: default
2020-08-30 18:37:51.572 INFO 16216 --- [JavaFX-Launcher] o.s.boot.SpringApplication : Started application in 2.445 seconds (JVM running for 3.681)
Exception in Application start method
Exception in thread "main" 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 org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
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/java.net.urlclassloader.defineClass(UnkNown Source)
at java.base/java.net.urlclassloader.access$100(UnkNown Source)
at java.base/java.net.urlclassloader$1.run(UnkNown Source)
at java.base/java.net.urlclassloader$1.run(UnkNown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.urlclassloader.findClass(UnkNown Source)
at java.base/java.lang.classLoader.loadClass(UnkNown Source)
at org.springframework.boot.loader.Launchedurlclassloader.loadClass(Launchedurlclassloader.java:92)
at java.base/java.lang.classLoader.loadClass(UnkNown Source)
at org.controlsfx.control.CheckComboBox.createDefaultSkin(CheckComboBox.java:304)
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.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 sar.happycactus.tech.ExportFx.ExportFxApplication.start(ExportFxApplication.java:33)
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/java.net.urlclassloader.findClass(UnkNown Source)
at java.base/java.lang.classLoader.loadClass(UnkNown Source)
这是我的POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>sar.happycactus.tech</groupId>
<artifactId>Export-FX</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Export-FX</name>
<description>Export csv to xmls</description>
<properties>
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -->
<java.version>1.8</java.version>
<start-class>sar.happycactus.tech.ExportFx.ExportSpringBoot</start-class>
</properties>
<dependencies>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- controlsfx : checkcomboBox -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.17</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- write on excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- read from csv -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>sar.happycactus.tech.ExportFx.ExportSpringBoot</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。