1

How can I reduce the Maven Executable Jar file size. Currently its 255 MB. It is not allowing to deploy in Cloudformation.

I am doing the deployment via cloudformation --> Lambda and API Getway.

If I can reduce the file from 255 MB, Then my problem will be solved.

I have seen from the JAR file, This below 2 dependency are taking 195 MB.

<dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.11.931</version>
        </dependency>

        <dependency>
            <groupId>com.amazonaws.serverless</groupId>
            <artifactId>aws-serverless-java-container-spring</artifactId>
            <version>[0.1,)</version>

What I should to reduce it ?

Complete Pom XML file are -

Pom.xml -

4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.1.RELEASE com.myapp.app myapp-api 0.0.1-SNAPSHOT myapp-api Demo project for Spring Boot <java.version>1.8</java.version> org.springframework.boot spring-boot-starter-actuator com.amazonaws.serverless aws-serverless-java-container-springboot2 1.5.2 com.amazonaws aws-java-sdk 1.11.931 org.springframework.boot spring-boot-starter-data-mongodb org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-mail org.springframework.boot spring-boot-devtools runtime true com.amazonaws.serverless aws-serverless-java-container-spring [0.1,) org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test

      <dependency>
          <groupId>net.authorize</groupId>
          <artifactId>anet-java-sdk</artifactId>
          <version>2.0.6</version>
      </dependency>
      <dependency>
          <groupId>org.springframework.security</groupId>
          <artifactId>spring-security-test</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>io.jsonwebtoken</groupId>
          <artifactId>jjwt</artifactId>
          <version>0.9.1</version>
      </dependency>
      <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger2</artifactId>
          <version>2.9.2</version>
      </dependency>
      <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger-ui</artifactId>
          <version>2.9.2</version>
      </dependency>
      <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-bean-validators</artifactId>
          <version>2.9.2</version>
      </dependency>
      <dependency>
          <groupId>org.hibernate.validator</groupId>
          <artifactId>hibernate-validator</artifactId>
      </dependency>
      <dependency>
          <groupId>net.logstash.logback</groupId>
          <artifactId>logstash-logback-encoder</artifactId>
          <version>5.2</version>
      </dependency>
      <dependency>
          <groupId>org.glassfish.jaxb</groupId>
          <artifactId>jaxb-runtime</artifactId>
      </dependency>
      <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.8.7</version>
      </dependency>
      <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.15</version>
      </dependency>
      <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-ooxml</artifactId>
          <version>3.15</version>
      </dependency>
  </dependencies>

  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.1.0</version>
              <configuration>
                  <excludes>
                      <exclude>*/.xml</exclude>
                  </excludes>
                  <archive>
                      <compress>true</compress>
                  </archive>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
              <configuration>
                  <excludes>
                      <exclude>
                          <groupId>org.projectlombok</groupId>
                          <artifactId>lombok</artifactId>
                      </exclude>
                  </excludes>
              </configuration>
          </plugin>
      </plugins>

  </build>

</project>
Lii
  • 11,553
  • 8
  • 64
  • 88
Atique Ahmed
  • 308
  • 4
  • 16
  • Is there any dependency are there which I need to add in Pom.xml ? – Atique Ahmed Jun 01 '22 at 10:43
  • 1
    What dependencies do you already have in there? You need to check the content of the JAR, and what you really need and don't need. Adding dependencies in the pom.xml will just increase the file size, you need to remove them – dunni Jun 01 '22 at 10:46
  • @dunni - I added the pom.xml. All the dependency are useful. – Atique Ahmed Jun 01 '22 at 10:50
  • And all those dependencies account for the file size? No other resources, like images or so, in the JAR? – dunni Jun 01 '22 at 10:51
  • @dunni - No. In the application properties I am doing the configuration. -- spring.servlet.multipart.enabled=true spring.servlet.multipart.file-size-threshold=2KB spring.servlet.multipart.max-file-size=200MB spring.servlet.multipart.max-request-size=215MB file.upload-dir=/home/pathofmyfile/myfile – Atique Ahmed Jun 01 '22 at 11:00
  • Well, in the end we cannot guess what the problem is, we don't have the JAR file to inspect it. You have to open it and look what files take the size. – dunni Jun 01 '22 at 11:01
  • @dunni - Can you please let me know how to do that ? How I can inspect my Jar, and check what file take the size. I am new to this. – Atique Ahmed Jun 01 '22 at 11:01
  • A JAR file is just a zip file, take any Unzip utility and extract it. – dunni Jun 01 '22 at 11:02
  • @dunni - Thanks a lot, Last question, Is there any specific folder or file, I should look at ? – Atique Ahmed Jun 01 '22 at 11:10
  • No, again, we don't know what you have in that JAR. You have to look through all folders to find any large files or folders. – dunni Jun 01 '22 at 11:11
  • @dunni - I check, AWS SDK are taking 193 MB. Above SDK dependency I am using. which I have mentioned in the POM XML – Atique Ahmed Jun 01 '22 at 11:38
  • Does this answer your question? [Can I lower AWS dependency size since I'm not using all of the services?](https://stackoverflow.com/questions/41751382/can-i-lower-aws-dependency-size-since-im-not-using-all-of-the-services) – y434y Jun 01 '22 at 12:41

1 Answers1

1

This is issue is resolved, I am using AWS Dependency -

<dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.11.931</version>
        </dependency>

I don't need all the dependency, I need only S3 and Lambda. So Have remove this dependency. It decrease my Jar file. 255 MB to 50 MB.

Atique Ahmed
  • 308
  • 4
  • 16
  • 1
    If this solves your problem then you should mark your own answer as accepted! – Lii Aug 29 '22 at 08:25