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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...