4

I'm building a project where the final war/jar size is very big. I am not sure how to reduce the size of the jar.

How to build only the jars required for the project?

Currently we just given maven build plugin in the dependencies and artifact id on the top which builds the war or jar

Please advise.

Thanks.

Robby Cornelissen
  • 81,630
  • 19
  • 117
  • 142
user2323036
  • 1,387
  • 5
  • 18
  • 27

2 Answers2

3

use dependency:analyze on your project to analyze used and unused dependencies, so you can exclude unwilling dependency files, i search a lot for a plugin to do it automatically, but I get disappointed in it. if you find please inform me.

https://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html

Mahdi Rajabi
  • 522
  • 1
  • 4
  • 11
2

JAR files typically don't include dependencies, so unless you're building a so-called fat JAR, they should never get very big.

For WAR files:

  • Remove unneeded dependencies from your POM.
  • Optionally, move static assets (images etc.) to a web server instead of including them in your application.
  • If you have dependencies that are being used by multiple applications, include them on the application server level instead of inside your WAR file.
Robby Cornelissen
  • 81,630
  • 19
  • 117
  • 142