Spring Boot 2.2.1 Create two jar's while Build [duplicate] - spring

This question already has answers here:
Why spring boot generates jar or war file with .original extension?
(2 answers)
Closed 3 years ago.
I am working on Spring boot version 2.2.1.RELEASE.While building my project two jar's will created having types executable jar file and original file as given below
The reason for this is
Maven first builds my project and packages my classes and
resources into a jar (${artifactId}.jar) file.
Then, repackaging happens. In this goal, all the dependencies
mentioned in the pom.xml are packaged inside a new WAR
(${artifactId}.jar) and the previously generated war is renamed to
${artifactId}.jar.original.
Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.data.MainService</mainClass>
</configuration>
</plugin>
</plugins>
</build>
How can we avoid to create ORIGINAL File type jar file.
Is there any disable /excluding technique available in maven.
Am also tried following <build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.data.MainService</mainClass>
</configuration>
</plugin>
</plugins>
</build>

As per the implementation jar.original is expected. Nothing to worry about.
Re packaging creates new jar file and renames old one to jar.original
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins.html#build-tool-plugins-repackage-implementation

Related

Spring Boot Admin - How to show app version (build-info) in wallboard?

I see on the web some images refferred to Spring Boot Admin showing the app version in the wallboard page.
I'm using latest version of SBA, currently 2.1.6 and i can't see the versions in the wallboard.
I see something like this.
Reading the documentation it seems that a maven plugin is needed:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I added it in the pom.xml of a micro-service and I restarted all docker swarms stacks (including SBA) but no changes.
I did some search but I can't find any reference.
The 'spring-boot-maven-plugin' is required to generate the build-info in
/target/classes/META-INF/build-info.properties
Spring Boot Admin picks up the build info including the application version from this file. Please check if this file is generated.
You need to execute the maven plugin first or just run
mvn clean install
For Spring Boot applications
The easiest way 😄 to show the version, is to use the build-info goal from the spring-boot-maven-plugin, which generates the META-INF/build-info.properties.
1) Change/add the plugin in the pom.xml as below👇
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
2) Delete 🚮 your target folder and do a mvn clean install🧹
3) Restart your app and check the version is there 👏
I did so and it worked.
Src.➡Show Version in Application List
Dirty fix
If the previous solution does not work...
You can read the properties from the META-INF (in the jar) and concatenate it to the app name (here: myApp-service).
1) Do the previous step 👆 (add goal in maven plugin)
2) Add in the properties:
spring.config.import=classpath:META-INF/build-info.properties
spring.application.name=myApp-service ${build.version}
3) Check the result (image below 📸 )
Src.➡spring-boot-maven-plugin build-info.properties

When does a Maven plugin uses the POM in the current directory?

I use the Versions Maven Plugin to check for updates of my dependencies. Therefore I added the following lines to my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions-plugin.version}</version>
<configuration>
<rulesUri>classpath:///rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>versionrules</groupId>
<artifactId>versionrules</artifactId>
<version>1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
But this configuration is not used if I run the Versions Maven Plugin from the commandline in the same directory as the pom.xml. The only way to use my own configuration is to put this plugin configuration in a profil and execute this profil during the Maven run.
Is there a way to run the Versions plugin on the commandline and to configure it via the pom.xml? I am sure my questions does not only apply to the Versions plugin, but to any Maven plugin.
This can be done by using an execution id default-cli in your execution definition the configuration will be used during the execution on command line (using the current configuration) furthermore since Maven 3.3.1 you can use things like:
mvn version:set#second-cli
which means you can do a different configuration for command line in the pom file:
Just by simply separating them by different id
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5.</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
...
</configuration>
</execution>
<execution>
<id>second-cli</id>
<configuration>
....
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
So this means you can have different configurations for running on command line by giving the id.

using spring-boot-maven-plugin with exec classifier, but can't run the app from IDE anymore

I am working on Spring Boot 1.5.9 application, and I am generating a jar that contains a Spring Boot application, but that can also be imported as part of another project.
Therefore, I am using below config to generate 2 jars : the exec, and the regular lib ones.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
However, now that I have this, I am not able to run the application from my IDE (Intellij) anymore, as it's not finding the application.yml.
I am sure there's a trick, but I can't find anything.. Any idea ?
I ended up using Maven profiles :
<profiles>
<profile>
<id>makeRelease</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I make the release, I am calling this profile (maven with argument -P makeRelease) so that it generates the 2 jars.
The rest of the time, the regular behavior applies.

Excluding JAR Files From the EAR using maven

My EAR includes 8 JAR files which are in the root of my EAR. I want to delete two of them for my final deployment EAR package.
I was trying do this as it is described here:
https://maven.apache.org/plugins/maven-ear-plugin/examples/excluding-files-from-ear.html
But seem not to work.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>test1.jar,test2.jar</packagingExcludes>
</configuration>
...
</plugin>

I don't want to include external jar in my maven war

I don't want to include external jars when I build a war.What should I do?
Though not sure about why are you thinking to exclude the jar files, but yes you can do that if you are using maven-war-plugin
This will work out
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
This a whole bunch of configuration plugin that excludes all .jar files.
This source explains about that and even regex patterns that can be used.

Resources