User Tools

Site Tools


maven:build-executable-jar

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
maven:build-executable-jar [2023/07/06 04:16] – removed - external edit (Unknown date) 127.0.0.1maven:build-executable-jar [2023/07/06 04:16] (current) – ↷ Page name changed from maven:build-executable-jar-with-all-dependencies to maven:build-executable-jar odefta
Line 1: Line 1:
 +====== Build a complete executable jar file containing all the other jar dependencies (as classes inside it) ======
  
 +For this we can use the maven shade plugin, so we'll need to add something like this to our main pom.xml file:
 +
 +<code xml>
 +<build>
 +        <plugins>
 +            <plugin>
 +                <groupId>org.apache.maven.plugins</groupId>
 +                <artifactId>maven-shade-plugin</artifactId>
 +                <version>3.5.0</version>
 +                <executions>
 +                    <execution>
 +                        <phase>package</phase>
 +                        <goals>
 +                            <goal>shade</goal>
 +                        </goals>
 +                        <configuration>
 +                            <transformers>
 +                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
 +                                    <mainClass>com.dovsoft.mft.Main</mainClass>
 +                                </transformer>
 +                            </transformers>
 +                        </configuration>
 +                    </execution>
 +                </executions>
 +            </plugin>
 +        </plugins>
 +</build>
 +</code>
 +
 +====== Create an executable jar but without any dependency ======
 +
 +For this we can use maven jar plugin - add this to main pom.xml file:
 +
 +<code xml>
 +<build>
 +        <plugins>
 +            <plugin>
 +                <groupId>org.apache.maven.plugins</groupId>
 +                <artifactId>maven-jar-plugin</artifactId>
 +                <version>3.3.0</version>
 +                <configuration>
 +                    <archive>
 +                        <manifest>
 +                            <mainClass>com.dovsoft.mft.Main</mainClass>
 +                        </manifest>
 +                    </archive>
 +                </configuration>
 +            </plugin>
 +        </plugins>
 +</build>
 +</code>