Executable JAR

To create an executable uber JAR, one simply needs to set the main class that serves as the application entry point:

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>3.0.0</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <transformers>
  17. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  18. <mainClass>org.sonatype.haven.HavenCli</mainClass>
  19. </transformer>
  20. </transformers>
  21. </configuration>
  22. </execution>
  23. </executions>
  24. </plugin>
  25. </plugins>
  26. </build>
  27. ...
  28. </project>

This snippet configures a special resource transformer which sets the Main-Class entry in the MANIFEST.MF of the shaded JAR. Other entries can be added to the MANIFEST.MF as well via key-value pairs in the <manifestEntries> section:

  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-shade-plugin</artifactId>
  8. <version>3.0.0</version>
  9. <executions>
  10. <execution>
  11. <phase>package</phase>
  12. <goals>
  13. <goal>shade</goal>
  14. </goals>
  15. <configuration>
  16. <transformers>
  17. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  18. <manifestEntries>
  19. <Main-Class>org.sonatype.haven.ExodusCli</Main-Class>
  20. <Build-Number>123</Build-Number>
  21. </manifestEntries>
  22. </transformer>
  23. </transformers>
  24. </configuration>
  25. </execution>
  26. </executions>
  27. </plugin>
  28. </plugins>
  29. </build>
  30. ...
  31. </project>