Maven Assembly 插件针对 JavaFx 17 发出警告

问题描述 投票:0回答:2

我在构建一个简单的 Java FX 示例时看到了一些警告,该示例也使用了 maven- assembly-plugin - 程序集警告输出为:

    [INFO] [INFO] --- maven-assembly-plugin:3.3.0:single (default) @ hellofx ---
    [INFO] Reading assembly descriptor: src/main/assembly/zip.xml
    [WARNING] Failed to build parent project for org.openjfx:javafx-controls:jar:17.0.1
    [WARNING] Failed to build parent project for org.openjfx:javafx-controls:jar:17.0.1
    [WARNING] Failed to build parent project for org.openjfx:javafx-graphics:jar:17.0.1
    [WARNING] Failed to build parent project for org.openjfx:javafx-graphics:jar:17.0.1
    [WARNING] Failed to build parent project for org.openjfx:javafx-base:jar:17.0.1
    [WARNING] Failed to build parent project for org.openjfx:javafx-base:jar:17.0.1

这些警告似乎特定于版本 17 及更早版本的 JavaFx 库 版本例如11版还可以。

要重现一个 Maven 项目,请使用以下目录结构创建

    openjfx-assembly-warnings\data\someData.txt
    openjfx-assembly-warnings\scripts\run.bat
    openjfx-assembly-warnings\src\main\assembly\zip.xml
    openjfx-assembly-warnings\src\main\java\HelloFX.java
    openjfx-assembly-warnings\pom.xml

文件内容为:

一些数据.txt

This file represents some data 
to be zipped up along with the 
application jar file

运行.bat

    java -cp ".;lib\*" HelloFX

zip.xml

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 
       http://maven.apache.org/xsd/assembly-1.1.2.xsd">
      <id>zip</id>
      <includeBaseDirectory>true</includeBaseDirectory>
      <formats>
        <format>zip</format>
      </formats>
      <fileSets>
        <fileSet>
          <directory>${project.basedir}/scripts</directory>
          <outputDirectory>/</outputDirectory>
        </fileSet>
        <fileSet>
          <directory>${project.basedir}/data</directory>
          <includes>
            <include>*</include>                
          </includes>           
          <outputDirectory>/data</outputDirectory>
        </fileSet>      
      </fileSets>
      <dependencySets>
        <dependencySet>
          <outputDirectory>/lib</outputDirectory>
        </dependencySet>
      </dependencySets>
    </assembly>

HelloFX.java

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;

    public class HelloFX extends Application {

      @Override
      public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + 
                            javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
      }

      public static void main(String[] args) {
        launch();
      }
    }

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>
      <name>hellofx</name>
      <groupId>com.test</groupId>
      <artifactId>hellofx</artifactId>
      <version>1.0.1</version>
      <packaging>jar</packaging>
      <url>http://maven.apache.org</url>
      <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.openjfx</groupId>
          <artifactId>javafx-controls</artifactId>
          <version>17.0.1</version>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
              <release>11</release>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>java</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <mainClass>HelloFX</mainClass>
            </configuration>
          </plugin>  
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <appendAssemblyId>false</appendAssemblyId>
                  <descriptors>
                    <descriptor>src/main/assembly/zip.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>       
        </plugins>
      </build>
    </project>

要重新创建警告输出,请运行 Maven 命令:mvn clean install

除了使用之外,是否有人有办法防止出现警告 Java FX 依赖项的早期版本?

感谢您对此的任何想法或提示

maven javafx plugins
2个回答
0
投票

您可以使用提供的 javafx 依赖范围:

 <dependency>
   <groupId>org.openjfx</groupId>
   <artifactId>javafx-controls</artifactId>
   <version>17.0.1</version>
   <scope>provided</scope>
 </dependency>

并将您的程序称为:

java --module-path PATH_TO_JAVAFX_LIB_DIRECTORY --add-modules javafx.controls -cp hellofx.jar HelloFX

-3
投票
© www.soinside.com 2019 - 2024. All rights reserved.