【问题标题】:Override file in META-INF覆盖 META-INF 中的文件
【发布时间】:2021-07-02 12:38:04
【问题描述】:

在我的项目中,我有一个依赖项,其 Jar 文件包含文件 META-INF/org/languagetool/language-module.properties。出于某种特殊原因,我想用我自己的版本完全替换这个文件。我搜索了一下,发现我可以通过简单地创建文件来将文件添加到META-INF

src/resources/META-INF/org/languagetool/language-module.properties

只要我要添加的文件和已经存在的文件具有不同的名称,这将有效。但如果它们具有相同的名称,maven-assembly-plugin 将使用依赖项中的文件而不是使用我的文件。我该如何解决?

maven-assembly-plugin的配置:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
    <archive>
        <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
        <mainClass>com.github.vatbub.autoHotkeyNounReplacer.CreateAutoHotkeyScriptKt</mainClass>
        </manifest>
        <manifestEntries>
        <Implementation-Build>20210702123553</Implementation-Build>
        <Custom-Implementation-Build>20210702123553</Custom-Implementation-Build>
        </manifestEntries>
    </archive>
    <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    </configuration>
</plugin>

【问题讨论】:

    标签: java maven maven-assembly-plugin


    【解决方案1】:

    我自己找到了答案:maven shade 插件可以更好地控制如何创建组装的 jar。因此,我用具有以下配置的 maven-shade-plugin 替换了 maven-assembly-plugin:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.4</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <filters>
                <filter>
                    <artifact>org.languagetool:*</artifact>
                    <excludes>
                        <exclude>META-INF/org/languagetool/language-module.properties</exclude>
                    </excludes>
                </filter>
            </filters>
            <shadedArtifactAttached>true</shadedArtifactAttached>
            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
            <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <manifestEntries>
                        <Main-Class>${mainClass}</Main-Class>
                        <!-- custom manifest entries -->
                    </manifestEntries>
                </transformer>
            </transformers>
        </configuration>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 2013-03-20
      • 2016-10-02
      • 2014-08-14
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多