JavaFX Exception in thread “main” java.lang.NoClassDefFoundError: javafx/application/Application

前端 未结 11 1266
半阙折子戏
半阙折子戏 2020-12-01 08:09

I\'m getting this error

Exception in thread \"main\" java.lang.NoClassDefFoundError: javafx/application/Ap
plication
        at java.lang.ClassLoader.defineC         


        
11条回答
  •  粉色の甜心
    2020-12-01 08:14

    I know it may not be the "proper" way of launching an javafx application but i have struggled with this problem for some time and came up with a workaround that does not require to use any external packaging applications, force you to use ant or maven plugin (which conflicts with the shade plugin) etc...

    The solution uses Utils4j to load jfxrt dynamically at runtime. You cannot load it in a class extending javafx.application.Application, do it in a separate class and name it for example: Launcher

    import org.fuin.utils4j.Utils4J
    
    public class Launcher {
    
        public static void main(String[] args) {
            Utils4J.addToClasspath("file:///"+System.getProperty("java.home")+ File.separator+"lib"+File.separator+"jfxrt.jar");
    
    // CODE TO RUN YOUR CLASS THAT EXTENDS javafx.application.Application goes here.
    
        }
    }
    

    you can include Utils4j with your project (if using maven):

        
            org.fuin
            utils4j
            0.7.0
        
    

提交回复
热议问题