java - 减少 Spring Boot 可执行 jar Angular App 的磁盘空间

标签 java angular maven spring-boot

Maven项目:SpringBoot有一个SpringBoot启动类。 “resouces/public”文件夹中的 Angular 网站。

应用程序启动并提供公共(public)文件夹中的index.html。

我想减小 Spring Boot 应用程序的大小。我已经完成了 Angular 应用程序的修剪。

SpringBoot 中有哪些选项可以仅运行静态网站?我可以排除任何样板代码吗?

注意:这是一个 Maven 项目。

最佳答案

我能够在可执行 JAR 中保存约 13MB

  • SpringBoot 不含 hibernate 时约为 14MB(5MB)
  • Angular,删除 FONTS 文件夹为我节省了 ~8MB

我所做的是运行mvn dependency:tree

然后我查看了列表并通过更新 pom 并排除了 Hibernate:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot-version}</version>
                  <exclusions>
                    <exclusion>  <!-- declare the exclusion here -->
                      <groupId>org.hibernate</groupId>
                      <artifactId>hibernate-validator</artifactId>
                    </exclusion>
                  </exclusions> 
        </dependency>

依赖树

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.24:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.11:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.11:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.11:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.3.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.3.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.7.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.7.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.5.2.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test:jar:1.5.2.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.2.RELEASE:test
[INFO]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO]    |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO]    |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO]    |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO]    |  \- org.slf4j:slf4j-api:jar:1.7.16:compile
[INFO]    +- junit:junit:jar:4.12:test
[INFO]    +- org.assertj:assertj-core:jar:2.6.0:test
[INFO]    +- org.mockito:mockito-core:jar:1.10.19:test
[INFO]    |  \- org.objenesis:objenesis:jar:2.1:test
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO]    +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO]    |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO]    +- org.springframework:spring-core:jar:4.3.7.RELEASE:compile
[INFO]    \- org.springframework:spring-test:jar:4.3.7.RELEASE:test

关于java - 减少 Spring Boot 可执行 jar Angular App 的磁盘空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54791107/

相关文章:

angular - 如何在 Angular 2 中使用 MaterializeCSS

maven-2 - 配置一个 hudson maven 作业以在测试失败时继续构建,但仅在没有测试失败时部署

c# - 在 C# 中使用 lambda 的 Enumerable.Select 的 Java 等价物是什么?

java - 如何让 Eclipse 显示我的类中的 javadoc 而无需在 jar 中包含源代码

angular - 不能在 Angular 9 中使用 Ng-bootstrap

css - 使用 Angular 6 将图标添加到 mat-menu 的右上角

java - 从设备访问数据

java - spring-boot shutdown 兔子 NoClassDefFoundError

maven - 在 Tomcat 中部署 Maven 项目

html - Spring WAR 中的 CSS 文件返回 404