the executable JAR
For Java applications that can (and should) be executed on the Windows command line or Linux terminal session, create an executable jar.
This plugin works well for me:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>dev.sandbox.twitter.StreamTwitter</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin>
I run this on the command line like this:
c:\temp>java -cp target/twitter-1.0-SNAPSHOT.jar dev.sandbox.twitter.StreamTwitter Writing to File: \\Data\Twitter-raw\raw-fh\1417630549.json ... etc ...
the fat JAR
If I'm writing mapReduce code in Java, and referencing external POM files, I'll need to build a fat JAR that contains all the dependencies for Hadoop to successfully execute my code.
Adding this plugin has worked well for me on Hadoop 2.6.0:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> <configuration> <finalName>uber-${artifactId}-${version}</finalName> </configuration> </plugin>
If you try to run this "uber-*" jar from the command line, and get this error:
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
then add this filter to the POM (within the configuration section):
<filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters>
References
- [AvaJava] Building a JAR file that contains its dependencies
- [StackOverflow] Troubleshooting "Invalid Signature Digest"