缺少JavaFX应用程序类sample.Main [英] Missing JavaFX application class sample.Main

查看:1444
本文介绍了缺少JavaFX应用程序类sample.Main的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaFx项目在intellij构思中正常运行。在编辑配置中,我选择了主类为 sample.Main ,当单击intellij idea的运行按钮时,项目正常工作。

My JavaFx project is working properly in intellij idea. In edit configurations, I have chosen the main class as sample.Main and when clicking the run button of intellij idea, project works properly.

然后我使用构建工件将我的JavaFX项目转换为.jar文件。但是当尝试使用 java -jar project.jar 运行.jar时,会出现错误缺少JavaFX应用程序类sample.Main。我在两种场合都使用过相同的课程。那么为什么在运行.jar时输出错误?

Then I have converted my JavaFX project to a .jar file using build artifacts. But when trying to run .jar by using java -jar project.jar, there is an error "Missing JavaFX application class sample.Main". I have used same class in both occasions. So why does it output error while running .jar?

推荐答案

最后这对我有用。
文件 - >项目结构 - >工件 - >按+按钮 - >添加JAR - >从具有依赖项的模块。现在将有一个名为create JAR的apear接口来自模块。在那里选择您的确切主类。选择复制到输出目录并通过清单链接选项。 META_INF / MANIFEST.MF的目录通常采用java目录。选择资源目录是很好的。然后单击确定。将出现一个新窗口。单击Apply和OK.Now转到工具栏并单击Build - > Build Artifacts - > Build。您可以在项目编译器输出路径下找到构建的工件。如果您不知道项目编译器输出路径的确切位置,然后转到文件 - >项目结构 - >项目 - >项目编译器输出。在项目编译器输出路径的末尾,您可以看到artifacts文件夹。在那里您可以找到包含所有内置jar的文件夹。右键单击该文件夹,然后单击在文件中显示。您可以转到确切的文件夹你的内置罐子很容易。然后在那里打开终端并运行java -jar project.jar.project必须替换为你的应用程序名称。

Finally this worked for me. File-->Project Structure-->Artifacts-->press + button -->Add JAR-->From modules with dependencies. Now there will apear interface called create JAR from modules. Choose your exact Main Class there. Choose option "copy to the output directory and link via manifest". Directory for META_INF/MANIFEST.MF usually takes to java directory. It is good if you choose resources directory. Then click OK. A new window will appear.Click Apply and OK.Now go to the tool bar and click Build-->Build Artifacts-->Build.You can find built artifacts under the "project compiler output path".If you don't know exact location for "project compiler output path",then go File-->Project Structure-->Project-->Project compiler output. At the end of the project compiler output path you can see "artifacts" folder.There you can find a folder which consists all built jars.Right click the folder and click the "Show in Files".You can go to the exact folder having your built jars easily. Then open the terminal there and run "java -jar project.jar".project must be replaced by your application name.

这篇关于缺少JavaFX应用程序类sample.Main的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆