Maven-shade-plugin 检测到某些类文件存在于两个或多个 JAR 中

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

我正在尝试使用 maven-shade-plugin 但我收到警告:

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 定义 1 重叠资源:

  • 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 定义 2 个重叠资源:
  • 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 定义 1 个重叠资源:
  • META-INF/substrate/config/reflectionconfig.json maven-shade-plugin 检测到某些类文件存在于两个或多个 JAR 中。 发生这种情况时,只会将该类的一个版本复制到 超级罐子。通常这没有害处,您可以跳过这些 警告,否则尝试根据 mvn 手动排除工件 dependency:tree -Ddetail=true 和上面的输出。看 https://maven.apache.org/plugins/maven-shade-plugin/

此警告可能会发生变化(可能来自我的行为)。

我尝试用这个来修复它,但没有成功:

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

我开始尝试修复此警告,因为 Shadow-jar 由于错误而无法启动:

错误:缺少 JavaFX 运行时组件,需要运行 这个应用程序

请告诉我如何修复此错误并运行shade-jar?

我的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>
java maven javafx maven-shade-plugin
1个回答
1
投票

我用这个代替“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>

这个:https://stackoverflow.com/a/70809214/10946427

© www.soinside.com 2019 - 2024. All rights reserved.