简体   繁体   中英

Deploying Swing application with JavaFX content

I've written a Swing application that uses a JavaFX component and I'd like to package it for distribution, however I haven't been able to figure it out.

In Intellij Idea I selected File-> Project Structure-> artifacts and chose "from module". Next I selected Build-> Generate Ant Build and generated some Ant files. I modified the is line:

<fx:application id="JReader_id" name="JReader" mainClass="com.facetoe.jreader.JReader"/>

as described here to:

<fx:application id="JReader_id" name="JReader" mainClass="com.facetoe.jreader.JReader" toolkit="swing"/>

to indicate its a Swing application. Finally I built the .jar using Build-> Build Artifacts in Intellij and the .jar was created without errors. However when I attempt to run the .jar I get this error:

    ⇒ java -jar out/artifacts/JReader/JReader.jar
    java.lang.IllegalAccessException: Class com.javafx.main.Main can not access a member of class com.facetoe.jreader.JReader with modifiers "public static"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
    at java.lang.reflect.Method.invoke(Method.java:599)
    at com.javafx.main.Main.launchApp(Main.java:714)
    at com.javafx.main.Main.main(Main.java:871)

It looks like it cannot run the main method for some reason... Does anyone have any idea how I could fix this?

Ok I figured it out. The class containing my method was not public , so I made it public and everything works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM