'Java why is my jar file so big?

I have a pretty simple (And short) program that when compiled is somehow 26.9 MB?

I used a online java decompiler and all this came up: imgur link

My program uses one java file which is main.java:

}

Why is my program so large?



Solution 1:[1]

It seems that you're using a lot of external libraries (now when you provided the code seems that they pulled by Selenium) in your code and intellij kindly packs them together into one jar, so you can run your program without need to care about class path in runtime.

To reduce the size of your jar I can suggest the following approaches:

  1. Reduce amount of external libraries (imported classes). For example don't include java.io.* but only the class you're actually using.

  2. Build proper compilation script using ant or maven. Then your jar will include only your classes and will be very small relatively to what you have now. However to run your code you'll need to care about having all required libs in runtime.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1