Doralitze
Doralitze

Reputation: 192

How to make maven request the correct javafx dependancies on linux

I've got a java project build by maven, compiling and running fine on FreeBSD, Mac and Windows. However when I try to compile it on Linux I get the following error:

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)

Obviously it can't determine the fact that it's running on linux so I added

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

to the properties division of the pom.xml with no effect. This however has the effect, that other OS try to download the linux version, and aren't capable to run the software anymore (being expected but showing to me that I wrote that property correctly). I'm testing inside a fresh Ubuntu VM and the VM is capable of compiling and running other (non JFX) project fine. I'm officially out of ideas.

Edit: My current 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>

Upvotes: 9

Views: 4882

Answers (3)

Jerome Hordies
Jerome Hordies

Reputation: 41

None of the solutions worked for me using javafx 19, the javafx.platform property is referred in the pom of the dependency and can't be resolved even if I set the javafx.platform property in my pom.

BUT what did work was to pass the property to mvn :

mvn install -Djavafx.platform=linux

Upvotes: 2

msteiger
msteiger

Reputation: 2044

I was unable to reproduce the solution proposed by Doralitze. It seems that the <javafx.platform> property is overriden in org.openjfx.javafx by OS-specific profiles.

I managed to solve the issue by enforcing the exact jar with a classifier. For example:

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

Valid values are: linux, win, mac

In my opinion this is merely an ugly workaround, but surprisingly the official docs suggest the same approach: https://openjfx.io/openjfx-docs/#modular

Upvotes: 3

Doralitze
Doralitze

Reputation: 192

I was able to get it working by replacing <javafx.platform>linux</javafx.platform> with <javafx.platform>\%linux\%</javafx.platform>. A colleague suggested this to me but I've got no clue why this is working.

Upvotes: 2

Related Questions