Maven“阴影” JAR以“原始”为前缀。在文件名中 [英] Maven "shaded" JAR is prefixed with "original" in the file name

查看:255
本文介绍了Maven“阴影” JAR以“原始”为前缀。在文件名中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用shadeMaven2插件来构建一个捆绑在一起的所有Java依赖项的单片JAR。 pom.xml 中的相关部分非常简单:

I'm using the "shade" Maven2 plugin to build a monolithic JAR with all Java dependencies bundled together. The relevant section in pom.xml is pretty straightforward:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <finalName>${project.artifactId}-${project.version}-SHADED</finalName>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.mypackage.MyClass</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

但是,构建结果是奇数。看来这两个文件实际上是由这个Maven插件创建的:

However, the build results are odd. It seems that TWO files are actually created by this Maven plugin:

myartifact-1.0.0-SHADED.jar  (zero bytes)
original-myartifact-1.0.0-SHADED.jar  (10 MB)

JAR带有前缀original的文件已正确构建,并且运行正常。我想我可以重命名它以去掉那个前缀,并继续我的快乐方式。

The JAR file with prefix "original" is properly built, and functions just fine. I suppose I could just rename it to strip off that prefix, and go on my merry way.

然而,我非常好奇这里的阴影插件可能会发生什么。看起来原始文件是临时工作空间类型的东西,打算在进程结束时重命名,并且最终重命名根本不会完成。但是,没有明显的解释(即文件系统权限等)。有没有人见过这个?

However, I very curious as to what may be going on here with the "shade" plugin. It looks like the "original" file is temporary working space type thing, intended to be renamed at the end of the process, and that final renaming simply doesn't complete. There's no obvious explanation for that, though (i.e. filesystem permissions, etc). Has anyone ever seen this before?

推荐答案

Maven的构建步骤将创建jar target / artifact-version .jar

Maven's build steps will create the jar target/artifact-version.jar.

然后树荫插件运行。它通常将该jar重命名为 target / original-artifact-version.jar ,并为着色的JAR指定名称 target / artifact-version.jar

Then the shade plugin runs. It normally renames that jar to target/original-artifact-version.jar, and gives the shaded JAR the name target/artifact-version.jar.

但是,您正在配置Shade插件以使用其他名称。除非有充分的理由,否则我会从您的配置中删除< finalName> ,并使用Shade插件希望为您提供的内容。

However, you're configuring the Shade plugin to use a different name. Unless there's a good reason for that, I'd remove <finalName> from your configuration, and live with what the Shade plugin wants to give you.

这篇关于Maven“阴影” JAR以“原始”为前缀。在文件名中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆