java - 使用 java SDK 11.0.6 构建可执行 JavaFX 应用程序

标签 java maven javafx-11 jlink

我有一个 JavaFX 应用程序,已使用 Java SDK 1.8 成功构建并运行。我正在尝试将其移至 Java 11,最终目标是使用 Java 14,但无法创建可运行的 jar。为了尝试理解这个过程,我下载了 javafx helloFX 示例,并尝试按照 https://openjfx.io/openjfx-docs/#modular 中的说明进行操作。对于马文来说。当我运行 mvn clean javafx:jlink 时出现错误:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.openjfx:hellofx >-------------------------
[INFO] Building demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hellofx ---
[INFO] Deleting C:\Users\jungl\eclipse-workspace\helloFX\Maven\hellofx\target
[INFO]
[INFO] --- javafx-maven-plugin:0.0.3:jlink (default-cli) @ hellofx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\jungl\eclipse-workspace\helloFX\Maven\hellofx\src\main\resources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\jungl\eclipse-workspace\helloFX\Maven\hellofx\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.345 s
[INFO] Finished at: 2020-04-14T14:52:18+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.3:jlink (default-cli) on project hellofx: Error: jlink requires a module descriptor -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

pom.xml 是

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.openjfx</groupId>
  <artifactId>hellofx</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-controls</artifactId>
      <version>11</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.3</version>
        <configuration>
          <mainClass>HelloFX</mainClass>
      <jlinkImageName>hello></jlinkImageName>
      <jlinkZipName>hellozip></jlinkZipName>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
<!-- https://mvnrepository.com/artifact/com.zenjava/javafx-maven-plugin -->

有人能指出我正确的方向吗,因为我无法理解这个问题。

最佳答案

提供的示例的结构并不像教程所说的那样。 CommandLine文件夹下的maven版本已更新。如果您转到:..\CommandLine\Modular\Maven\helloFX 并输入命令 mvn clean javafx:ru​​n、clean javafx:jlink、target\hellofx\bin\launcher,它将按照教程中的说明运行。

关于java - 使用 java SDK 11.0.6 构建可执行 JavaFX 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61209656/

相关文章:

java - 在 Java 中,我将如何重新初始化 for 循环初始化表达式?

java - 无法在边缘 webDriver 上运行我的 Selenium 测试

java - 获取 java 异常 : java.net.MalformedURLException:无协议(protocol)

java - 自定义 Maven 插件托管和前缀解析

JavaFX 11 可编辑组合框抛出 IndexOutOfBoundsException

JavaFX 11 : IllegalAccessError when creating Label

java - 如何在java中动态检索常量?

java - Apache Axis2/Rampart + Maven

java - Maven - 我可以在应用程序运行时包含第三方依赖项吗?

javafx-11 - 如何修复 "Error: JavaFX runtime components are missing, and are required to run this application"?