[英]Missing dependencies when building to jar with javaFx and intellij IDEA
I am trying to build my project to a runnable jar in intellij IDEA;我正在尝试在 intellij IDEA 中将我的项目构建为一个可运行的 jar; I am using javaFx for the GUI.
我在 GUI 中使用 javaFx。 I have successfully run/built the project multiple times through development but now I have created an artifact as followed in another stackoverflow post and this didn't include the javafx dependency even though I selected it to and it's in the build path, My message is:
Error: JavaFX runtime components are missing, and are required to run this application
even though I have added the dependencies in build and to the environment variables.我已经通过开发成功地多次运行/构建了该项目,但现在我在另一个stackoverflow 帖子中创建了一个工件,尽管我选择了它并且它在构建路径中,但它不包含 javafx 依赖项,我的消息是:
Error: JavaFX runtime components are missing, and are required to run this application
即使我已在构建和环境变量中添加了依赖项Error: JavaFX runtime components are missing, and are required to run this application
。 Is there a solution?有解决办法吗?
Thanks谢谢
I had the same error message when trying to run a JAR file created with JavaFX 11 in IntelliJ.尝试在 IntelliJ 中运行使用 JavaFX 11 创建的 JAR 文件时,我收到了相同的错误消息。
You're just missing two additional steps:您只是缺少两个额外的步骤:
To do that in IntelliJ, it's:要在 IntelliJ 中做到这一点,它是:
File > Project Structure > Artifacts > click the "+" symbol > File > and then select all the .so files in the JavaFX folder.文件 > 项目结构 > 工件 > 单击“+”符号 > 文件 > 然后选择 JavaFX 文件夹中的所有 .so 文件。
scenario:设想:
you carefully follow "https://openjfx.io/openjfx-docs/#install-javafx", the "Non-modular with Maven"您仔细遵循“https://openjfx.io/openjfx-docs/#install-javafx”,即“非模块化 Maven”
you app does run inside IntelliJ您的应用程序确实在 IntelliJ 中运行
Yo cannot build a correct jar你不能构建一个正确的罐子
You DON'T want to fight with你不想和
..EXPORT / .. --wtf .... : --module-path $PATH_TO_FX --add-modules ..EXPORT / .. --wtf .... : --module-path $PATH_TO_FX --add-modules
We have to use an helper class.我们必须使用辅助类。
add the following class "Helper" and make it the "MAIN" class添加以下类“Helper”并使其成为“MAIN”类
public class Launcher {公共类启动器{
public static void main(String[] args) { App.main(args); }
} }
change refs in maven from you actual name (if starting from javafx site sample.. ) to this Launcher class:将 maven 中的 refs 从您的实际名称(如果从 javafx site sample.. 开始)更改为这个 Launcher 类:
from:从:
org.example.App org.example.App
to:到:
org.example.Launcher org.example.Launcher
add SHADE plug in to manven:在 manven 中添加 SHADE 插件:
<executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>project-classifier</shadedClassifierName> <outputFile>shade\\${project.artifactId}.jar</outputFile> <transformers> <transformer implementation= "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <!-- original: <mainClass>org.example.App</mainClass> --> <mainClass>org.example.Launcher</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin>
to run in intelliJ, change main class in "Edit Configuration" to "Launcher"要在 IntelliJ 中运行,请将“编辑配置”中的主类更改为“启动器”
... run "mvn clean!" ...运行“mvn clean!” :)
:)
PS: You can see ti in action here: PS:您可以在这里看到 ti 的运行情况:
https://github.com/ingconti/SampleJavaFxWithResize https://github.com/ingconti/SampleJavaFxWithResize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.