Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven "shaded" JAR is prefixed with "original" in the file name

Tags:

java

maven-2

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> 

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) 

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?

like image 831
Steve Perkins Avatar asked Nov 03 '10 15:11

Steve Perkins


People also ask

What is shaded jar in Maven?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

What is jar original in Maven?

jar file contains Spring boot framework class files having this contents while the . jar. original file contains actual class files of my application. Snapshot of target folder.

What does Maven shaded mean?

Together literally it means "jar-over-all-other-jars". "Shading" is the same as "package reallocation" which is needed for classes or resources that collide.


2 Answers

I know this question is old, but thought it was worth adding the following information.

I think the output originally desired by Steve is that given on this page of the maven-shade-plugin documentation.

<shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>jar-with-dependencies</shadedClassifierName> 
like image 112
Stewart Avatar answered Sep 22 '22 03:09

Stewart


Maven's build steps will create the 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.

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.

like image 20
Anon Avatar answered Sep 23 '22 03:09

Anon