Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude lib-provided from spring boot

My spring boot war is simply too large and I want to make some optimalisation. SPring boot has the option to run war with java -jar, that is why lib-provided (with all provided dependecies) is still inside the war even though the dependecies are not needed there (I will never run it as standalone). Can I somehow disable this clever functionality, so that I can save some space?

UPDATE: I am using Maven and spring boot maven plugin.

like image 962
Mejmo Avatar asked Nov 12 '15 14:11

Mejmo


People also ask

How do I exclude a class in spring boot?

If the class is not on the classpath, you can use the excludeName attribute of the annotation and specify the fully qualified name instead. Finally, you can also control the list of auto-configuration classes to exclude by using the spring. autoconfigure. exclude property.

How do you exclude specific dependencies from Spring-Boot-starter-parent?

Just override the version as explained here in the Spring Boot Reference Guide. Assuming you are using the spring-boot-starter-parent as the parent you can just add a <selenium. version> to your <properties> section to specify which version you want. This will make Spring Boot use the version you want.

What is Lib provided?

'provided' dependencies are placed in 'WEB-INF/lib-provided'. This is to avoid any clash when the war is deployed in a servlet container. 'WEB-INF/lib-provided' jars will only be used when war is executed as an application and the embedded server is used.


1 Answers

By Default Spring Boot Maven plugin will repackage your application into a executable WAR/JAR.

The original (i.e. non executable) artifact is renamed to .original by default but it is also possible to keep the original artifact using a custom classifier. refer the Spring Documentation

For Example:

If your app is named as MyApplication and you are trying to package it into a WAR, The following steps will happen:

  1. The application will first be built as usual and you would get MyApplication-0.0.1-SNAPSHOT.war
  2. Then spring boot maven plugin will repackage it into an executable WAR (with the same name) and it will rename the original packaged application to MyApplication-0.0.1-SNAPSHOT.war.original.
  3. You are now having two packaged applications:
    • MyApplication-0.0.1-SNAPSHOT.war (Spring boot executable)
    • MyApplication-0.0.1-SNAPSHOT.war.original(Non-Executable application)

You can either remove the Spring Boot Maven Plugin all together or use the Non-Executable version.

like image 91
Manish Kothari Avatar answered Oct 27 '22 01:10

Manish Kothari