【问题标题】:How to make maven request the correct javafx dependancies on linux如何使 maven 在 linux 上请求正确的 javafx 依赖项
【发布时间】:2019-04-10 15:06:07
【问题描述】:

我有一个由 maven 构建的 java 项目,在 FreeBSD、Mac 和 Windows 上编译和运行良好。但是,当我尝试在 Linux 上编译它时,出现以下错误:

The following artifacts could not be resolved: org.openjfx:javafx-controls:jar:${javafx.platform}:12, org.openjfx:javafx-graphics:jar:${javafx.platform}:12, org.openjfx:javafx-base:jar:${javafx.platform}:12: Could not find artifact org.openjfx:javafx-controls:jar:${javafx.platform}:12 in central (https://repo.maven.apache.org/maven2)

显然它无法确定它是在 linux 上运行的,所以我添加了

<javafx.platform>sources</javafx.platform>

到 pom.xml 的属性划分没有效果。然而,这会产生效果,即其他操作系统尝试下载 linux 版本,并且不再能够运行该软件(这是意料之中的,但向我展示了我正确地编写了该属性)。我正在一个新的 Ubuntu VM 中进行测试,该 VM 能够很好地编译和运行其他(非 JFX)项目。我正式没有想法。

编辑:我当前的 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>swengf</groupId>
    <artifactId>china</artifactId>
    <packaging>jar</packaging>
    <version>0.0-SNAPSHOT</version>
    <name>ferfehlt</name>
    <url>https://projects.isp.uni-luebeck.de/grp_f/sweng_f</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>10</java.version>
        <junit.version>5.4.1</junit.version>
        <javafx.version>12</javafx.version>
        <javafx.platform>linux</javafx.platform>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>swengf.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.18</version>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

  • 您是否尝试过使用 Maven 配置文件按操作系统版本激活?见stackoverflow.com/questions/18015178/…
  • javafx.platform 需要一个平台,例如macwinlinux。见pom
  • 我已经尝试过配置文件没有任何效果。
  • 我刚刚将 'sources' 切换为 'linux' 并调用了 mvn clean; mvn 包导致生效。
  • 除非你发布 pom,否则很难说有什么问题。

标签: java maven javafx


【解决方案1】:

我可以通过将&lt;javafx.platform&gt;linux&lt;/javafx.platform&gt; 替换为&lt;javafx.platform&gt;\%linux\%&lt;/javafx.platform&gt; 来使其正常工作。一位同事向我提出了这个建议,但我不知道为什么它会起作用。

【讨论】:

    【解决方案2】:

    我无法重现 Doralitze 提出的解决方案。似乎&lt;javafx.platform&gt; 属性在 org.openjfx.javafx 中被特定于操作系统的配置文件覆盖。

    我设法通过使用分类器强制执行确切的 jar 来解决问题。例如:

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11.0.2</version>
        <classifier>linux</classifier>
    </dependency>
    

    有效值为:linux, win, mac

    在我看来,这只是一个丑陋的解决方法,但令人惊讶的是官方文档提出了相同的方法:https://openjfx.io/openjfx-docs/#modular

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 2015-12-08
      • 2019-10-13
      • 2023-04-01
      • 2022-07-08
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 2019-03-10
      相关资源
      最近更新 更多