Search code examples
javamavenjavafxmaven-shade-plugin

Maven-shade-plugin has detected that some class files are present in two or more JARs


I'm trying to use the maven-shade-plugin but I get a warning:

javafx-controls-18.0.1-win.jar, javafx-graphics-18.0.1-win.jar, javafx-media-18.0.1-win.jar, javafx-web-18.0.1-win.jar define 1 overlapping resource:

  • META-INF/substrate/config/resourcebundles javafx-graphics-18.0.1-win.jar, javafx-media-18.0.1-win.jar, javafx-web-18.0.1-win.jar define 2 overlapping resources:
  • META-INF/substrate/config/jniconfig-x86_64-linux.json
  • META-INF/substrate/config/reflectionconfig-x86_64-linux.json javafx-base-18.0.1-win.jar, javafx-controls-18.0.1-win.jar, javafx-graphics-18.0.1-win.jar define 1 overlapping resource:
  • META-INF/substrate/config/reflectionconfig.json maven-shade-plugin has detected that some class files are present in two or more JARs. When this happens, only one single version of the class is copied to the uber jar. Usually this is not harmful and you can skip these warnings, otherwise try to manually exclude artifacts based on mvn dependency:tree -Ddetail=true and the above output. See https://maven.apache.org/plugins/maven-shade-plugin/

This watning is subject to change (possibly from my actions).

I tried to fix it with this, but it didn't work:

<filters>
    <filter>
        <artifact>*:*</artifact>
        <excludes>
           <exclude>META-INF/*</exclude>
        </excludes>
    </filter>
</filters>

I began to try to fix this warning due to the fact that shade-jar does not start due to an error:

Error: JavaFX runtime components are missing, and are required to run this application

Please tell me how to fix this error and run shade-jar?

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>TEST</artifactId>
    <version>1.0</version>
    <name>TEST</name>

    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.8.2</junit.version>
        <javafx.version>18.0.1</javafx.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>uk.co.caprica</groupId>
            <artifactId>vlcj</artifactId>
            <version>4.7.1</version>
        </dependency>
        <dependency>
            <groupId>uk.co.caprica</groupId>
            <artifactId>vlcj-javafx</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.test.Main</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                    <source>18</source>
                    <target>18</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.test/com.test.Main</mainClass>
                            <launcher>TEST</launcher>
                            <jlinkZipName>TEST</jlinkZipName>
                            <jlinkImageName>TEST</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                            <compress>2</compress>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Solution

  • I used this instead "maven-shade-plugin"

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>com.example.Launcher</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>
    

    And this: https://stackoverflow.com/a/70809214/10946427