Exception in init method - JavaFX

后端 未结 2 966
囚心锁ツ
囚心锁ツ 2021-01-27 19:26

I get this exception after exporting into a .jar file with eclipse. IntelliJ says the same. But my program is working fine in eclipse.

Exception in thread \"main         


        
相关标签:
2条回答
  • 2021-01-27 20:03

    The javafx.application.Application class is going to be found in a javafx library; in an IDE such as eclipse you generally configure a project to refer to those libraries it needs for compilation and execution. When you put your code into a jar and run it outside the IDE, you need to provide the library to the runtime a different way.

    A standard way to do this is to set a classpath which has references to both the application jar and to any libraries it needs; the DOS command to do this would look something like:

    set classpath=c:\myProjects\myApplication\myJar.jar;c:\java\libaries\javafx\jfxrt.jar
    

    and then java would have access to the classes in both those jar files

    0 讨论(0)
  • 2021-01-27 20:04

    Oracle JDK includes JavaFX on the classpath from version 1.8 onwards; if you upgrade your JDK to version 8 or later it should run. I do not recommend building production-level JavaFX applications with versions prior to Java 8 anyway.

    If you really do want to use Java 7, consider using the built-in JavaFX deployment tools to build the jar, instead of the vanilla "create executable jar" from eclipse. These will properly build a jar file that includes the FX runtime, if needed. The easiest way to do this in Eclipse is to install e(fx)clipse (an Eclipse plugin); there's a tutorial which includes steps to build the jar file.

    0 讨论(0)
提交回复
热议问题