CopyPastor

Detecting plagiarism made easy.

Score: 0.8069170117378235; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-08-13
by Anar Sultanov

Original Post

Original - Posted on 2009-02-26
by Matthew McCullough



            
Present in both answers; Present only in the new answer; Present only in the old answer;

**[maven-jar-plugin][1]** you use is a very basic plugin that enables to generate a JAR, but it does not add the maven dependencies inside the final JAR.
To create an executable fat jar, consider using one of the following plugins:
**[maven-assembly-plugin][2]**
This plugin adds all dependencies inside the final JAR.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.1</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.example.Authentication</mainClass> </manifest> </archive> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
[**maven-shade-plugin**][3]
This plugin adds all dependencies inside the final JAR and executes shading (i.e. renaming)
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.1</version> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.example.Authentication</mainClass> </transformer> </transformers> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin>

[1]: https://maven.apache.org/plugins/maven-jar-plugin/ [2]: http://maven.apache.org/plugins/maven-assembly-plugin/ [3]: https://maven.apache.org/plugins/maven-shade-plugin/

Taking Unanswered's answer and reformatting it, we have:
<!-- language: xml -->
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build>
Next, I would recommend making this a natural part of your build, rather than something to call explicitly. To make this a integral part of your build, add this plugin to your `pom.xml` and bind it to the `package` lifecycle event. However, a gotcha is that you need to call the `assembly:single` goal if putting this in your pom.xml, while you would call 'assembly:assembly' if executing it manually from the command line.
<!-- language: xml -->
<project> [...] <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-my-jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> [...] </plugins> [...] </build> </project>

        
Present in both answers; Present only in the new answer; Present only in the old answer;