【发布时间】: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需要一个平台,例如mac、win或linux。见pom。 -
我已经尝试过配置文件没有任何效果。
-
我刚刚将 'sources' 切换为 'linux' 并调用了 mvn clean; mvn 包导致生效。
-
除非你发布 pom,否则很难说有什么问题。