To make an executable Java jar or to deploy Java jar to a system without dependency jars (eg. Spark app somehow won’t download required Maven dependencies), add these lines to pom.xml file of a Maven Java project directly under root tag to make a fat jar:

<build>
  <plugins>
    <plugin>

      <!--make single jar-->
      <artifactId>maven-assembly-plugin</artifactId>                
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
                
      <!--config-->
      <configuration>

        <!--make fat jar with dependencies-->
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <appendAssemblyId>false</appendAssemblyId>
                    
        <!--set executable class-->
        <archive>
          <manifest>
            <mainClass>some.package.App</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

 

Advertisements