Rename files inside a jar using some maven plugin

被刻印的时光 ゝ 提交于 2020-01-14 19:51:31

问题


I have a jar build by maven-shade-plugin. It contains META-INF/services with several files. These files have wrong names (because of the bug https://issues.apache.org/jira/browse/MSHADE-182). I'd like to rename these files.

What is the easiest way of doing this with maven?


回答1:


Dirty hack, but it works for me

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <echo message="unjar" />
                            <unzip src="${project.build.directory}/${artifactId}-${version}.jar" dest="${project.build.directory}/unpacked/" />
                            <echo message="rename service providers in META-INF/services" />
                            <move todir="${project.build.directory}/unpacked/META-INF/services" includeemptydirs="false">
                                <fileset dir="${project.build.directory}/unpacked/META-INF/services"/>
                                <mapper type="glob" from="*" to="${shade.package}.*"/>
                            </move>
                            <echo message="jar back" />
                            <jar destfile="${project.build.directory}/${artifactId}-${version}.jar" basedir="${project.build.directory}/unpacked" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


来源:https://stackoverflow.com/questions/33825743/rename-files-inside-a-jar-using-some-maven-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!