简体   繁体   English

用JavaFX内容部署Swing应用程序

[英]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. 我已经编写了一个使用JavaFX组件的Swing应用程序,并且希望将其打包以进行分发,但是我一直无法弄清楚。

In Intellij Idea I selected File-> Project Structure-> artifacts and chose "from module". 在Intellij Idea中,我选择了File-> Project Structure-> artifacts,然后选择“ from module”。 Next I selected Build-> Generate Ant Build and generated some Ant files. 接下来,我选择Build-> Generate Ant Build并生成一些Ant文件。 I modified the is line: 我修改了is行:

<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. 指示其是Swing应用程序。 Finally I built the .jar using Build-> Build Artifacts in Intellij and the .jar was created without errors. 最后,我建立了.jar采用建设- >内建的IntelliJ文物和将.jar没有错误已创建。 However when I attempt to run the .jar I get this error: 但是,当我尝试运行.jar时,出现此错误:

    ⇒ 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? 似乎由于某种原因它无法运行main方法...有人知道我该如何解决吗?

Ok I figured it out. 好吧,我知道了。 The class containing my method was not public , so I made it public and everything works fine now. 包含我的方法的类不是public ,因此我将其public ,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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