Useful link https://www.baeldung.com/executable-jar-with-maven#bd-thymeleaf-4
The command to create a new maven project
Code Block | ||
---|---|---|
| ||
mvn archetype:generate -DgroupId=com.celestial -DartifactId=jaxrs_bos-example -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false |
Where -DartifactId=jaxrs_bos-example is the project name, maven creates a folder with this name. Replace jaxrs_bos-example with your project's name.
Where -DgroupId=com.celestial is your organisation's domain. Replace com.celestial with your organisation's domain.
Linking maven projects together - using maven modules
...
Add the following to your pom.xml
...
to build jar without external libraries included in the build
Code Block | ||
---|---|---|
| ||
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <mainClass>com.celestial.AClass</mainClass> </manifest> </archive> </configuration> </plugin> |
OR you can use the shade plugin to build jar with external libraries included in the build
Code Block | ||
---|---|---|
| ||
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.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.celestial.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin> |
OR
Code Block | ||
---|---|---|
| ||
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.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.lbg.coh2.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
|
Springboot Applications
When working with Sprinboot, use this plugin
Code Block |
---|
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
com.celestial.vatcsl.VatCalculatorServiceApplication
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> |
Latest Maven plugin that builds an executable with MainClass path
Code Block |
---|
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>kafka_demo</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.celestial.kafka.producer.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> |