Ke10 Ke10 - 1 year ago 103
Java Question

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


Why is my program so large?

Answer Source

As said above, IntelliJ will package the dependencies into the created JAR file. You can see this by extracting the JAR jar xf file.jar file and taking a look in the contents.

What you can do is (as suggested) use Maven ( this will allow you to create Dependencies that you can then supply to your code on the classpath.

With IntelliJ click File > New > Project,

Pick Maven from the list and choose a Project SDK.

Next give your project a Group ID ( and Artifact ID (myproject); leave Version as is for now.

Now, give you project a local name (this will be the folder that gets created on your IdeaProjects directory.

IntelliJ will popup a message to you saying that "Maven projects need to be imported", I always Enable Auto-Import and then just maintain the pom.xml file.

This will create you a project, find you pom.xml file: it will look something like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""


            <version>2.53.1</version><!-- Pick a different version if needed -->

Now you can package your project by running mvn package from the terminal, and your jar file will be saved into a target directory. It will be very small as it will contain only your code.

To run the program, you can then do the following:

mvn exec:java -Dexec.mainClass="" -Dexec.args="space separated arguments"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download