2021年 最新 多阶段构建dockerfile实现java源码编译打jar包并做成镜像

简介: 多阶段构建指在Dockerfile中使用多个FROM语句,每个FROM指令都可以使用不同的基础镜像,并且是一个独立的子构建阶段。使用多阶段构建打包Java应用具有构建安全、构建速度快、镜像文件体积小等优点.

背景信息

镜像构建的通用问题

镜像构建服务使用Dockerfile来帮助用户构建最终镜像,但在具体实践中,存在一些问题:

Dockerfile编写有门槛

开发者(尤其是Java)习惯了语言框架的编译便利性,不知道如何使用Dockerfile构建应用镜像。


镜像容易臃肿

构建镜像时,开发者会将项目的编译、测试、打包构建流程编写在一个Dockerfile中。每条Dockerfile指令都会为镜像添加一个新的图层,从而导致镜像层次深,镜像文件体积特别大。


存在源码泄露风险

打包镜像时,源代码容易被打包到镜像中,从而产生源代码泄漏的风险。


多阶段构建优势

针对Java这类的编译型语言,使用Dockerfile多阶段构建,具有以下优势:

保证构建镜像的安全性

当您使用Dockerfile多阶段构建镜像时,需要在第一阶段选择合适的编译时基础镜像,进行代码拷贝、项目依赖下载、编译、测试、打包流程。在第二阶段选择合适的运行时基础镜像,拷贝基础阶段生成的运行时依赖文件。最终构建的镜像将不包含任何源代码信息。


优化镜像的层数和体积

构建的镜像仅包含基础镜像和编译制品,镜像层数少,镜像文件体积小。


提升构建速度

使用构建工具(Docker、Buildkit等),可以并发执行多个构建流程,缩短构建耗时。


使用多阶段构建Dockerfile

以Java Maven项目为例,在Java Maven项目中新建Dockerfile文件,并在Dockerfile文件添加以下内容。

说明 该Dockerfile文件使用了二阶段构建。


第一阶段:

选择Maven基础镜像(Gradle类型也可以选择相应Gradle基础镜像)完成项目编译,拷贝源代码到基础镜像并运行RUN命令,从而构建Jar包。


第二阶段:

拷贝第一阶段生成的Jar包到OpenJDK镜像中,设置CMD运行命令。


方案一:


通俗易懂篇:


# First stage: complete build environment
FROM maven:3.5.0-jdk-8-alpine AS builder
# add pom.xml and source code
ADD ./pom.xml pom.xml
ADD ./src src/
# package jar
RUN mvn clean package
# Second stage: minimal runtime environment
From openjdk:8-jre-alpine
# copy jar from the first stage
COPY --from=builder target/my-app-1.0-SNAPSHOT.jar my-app-1.0-SNAPSHOT.jar
EXPOSE 8080
CMD ["java", "-jar", "my-app-1.0-SNAPSHOT.jar"]


方案二:


对于一个 Java 应用,如果要部署到 Kubernetes,首先需要创建一个容器镜像。这其实由两个步骤组成:


构建 Java 源代码,并打包成 JAR 文件。


把 JAR 文件和 JDK 组合在一起,创建出容器镜像。


在一般的构建过程中,这两个步骤是分开的。第一步由本地机器上的 Maven 或 Gradle 来完成,第二步使用 Docker 命令从 Dockerfile 中创建出镜像,并使用第一步构建出的本地 JAR 文件。


当需要使用某些公开容器镜像注册表(如 Docker Hub 和 Quay.io)提供的持续集成功能时,就不能再分成两个步骤,因为这些注册表只支持构建容器镜像,并没有提供应用构建的支持。


通过使用 Docker 提供的多阶段构建(multi-stage build)功能,我们可以很容易地把这两个步骤合成一个。


对于一个 Spring Boot 应用,下面的 Dockerfile 文件可以完成从源代码到镜像的构建。第一个阶段使用 Maven 镜像作为基础,在把 src 目录和 pom.xml 复制到镜像中之后, 使用 Maven 命令来编译源代码并打包。builder 是这个阶段的名称。在这个阶段完成之后,/build/target 目录中包含了所产生的 JAR 文件。


第二个阶段使用 OpenJDK 11 Alpine 镜像作为基础, COPY 命令把第一个阶段产生的 JAR 文件复制到当前镜像中。–from=builder 参数指定了复制的来源是第一个阶段产生的镜像。



大牛篇;


FROM maven:3.6.3-openjdk-8 AS builder
 #  AS builder 起别名
RUN mkdir /build
# 创建临时文件
ADD src /build/src
#将 src目录复制到临时目录
ADD pom.xml /build
# 将 pom文件复制到临时目录
RUN cd /build && mvn -B -ntp package
# 打包
FROM adoptopenjdk/openjdk8:alpine-jre
# 获取jre
COPY --from=builder /build/target/ems-0.0.1-SNAPSHOT.jar /ems.jar
#从标记点 拷贝jar包 并改名
CMD ["java", "-jar", "/ems.jar"]
# 声明运行方式


当使用 Docker 命令来构建这个 Dockerfile 文件之后,所得到的镜像中只包含 JAR 文件和 JDK。


IDEA文件结构如下:


image.png


命令行信息对比:

[root@localhost ~/myems]# docker build -t ems1:1.0 .
Sending build context to Docker daemon  32.77kB
Step 1/8 : FROM maven:3.6.3-openjdk-8 AS builder
 ---> d1b3f61d61f2
Step 2/8 : RUN mkdir /build
 ---> Running in 08cadf2db7b4
Removing intermediate container 08cadf2db7b4
 ---> 836eeb13f7fe
Step 3/8 : ADD src /build/src
 ---> b5d73ef7ed79
Step 4/8 : ADD pom.xml /build
 ---> 5e9a5ce77859
Step 5/8 : RUN cd /build && mvn -B -ntp package
 ---> Running in d92bbcd7ab54
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------------< com.baizhi:ems >---------------------------
[INFO] Building ems 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ems ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ems ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /build/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ ems ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /build/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ems ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /build/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ems ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.baizhi.EmsApplicationTests
12:11:00.101 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
12:11:00.200 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
12:11:02.814 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.baizhi.EmsApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
12:11:03.386 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.baizhi.EmsApplicationTests], using SpringBootContextLoader
12:11:03.427 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.baizhi.EmsApplicationTests]: class path resource [com/baizhi/EmsApplicationTests-context.xml] does not exist
12:11:03.428 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.baizhi.EmsApplicationTests]: class path resource [com/baizhi/EmsApplicationTestsContext.groovy] does not exist
12:11:03.428 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.baizhi.EmsApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
12:11:03.456 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.baizhi.EmsApplicationTests]: EmsApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
12:11:03.870 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.baizhi.EmsApplicationTests]
12:11:07.746 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/build/target/classes/com/baizhi/EmsApplication.class]
12:11:07.812 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.baizhi.EmsApplication for test class com.baizhi.EmsApplicationTests
12:11:11.875 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.baizhi.EmsApplicationTests]: using defaults.
12:11:11.876 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
12:11:12.008 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@29215f06, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@59505b48, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@4efac082, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6bd61f98, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@48aca48b, org.springframework.test.context.support.DirtiesContextTestExecutionListener@13fd2ccd, org.springframework.test.context.transaction.TransactionalTestExecutionListener@b9b00e0, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@506ae4d4, org.springframework.test.context.event.EventPublishingTestExecutionListener@7d4f9aae, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@72e5a8e, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@54e1c68b, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@53aac487, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@52b1beb6, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@273e7444, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@7db12bb6]
12:11:12.022 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@5d534f5d testClass = EmsApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2e3967ea testClass = EmsApplicationTests, locations = '{}', classes = '{class com.baizhi.EmsApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@670002, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@56528192, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@460d0a57, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@6af93788, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4a22f9e2, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@21bcffb5], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
12:11:12.467 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.2)
2021-06-29 12:12:10.365  INFO 69 --- [           main] com.baizhi.EmsApplicationTests           : Starting EmsApplicationTests using Java 1.8.0_282 on d92bbcd7ab54 with PID 69 (started by root in /build)
2021-06-29 12:12:10.368  INFO 69 --- [           main] com.baizhi.EmsApplicationTests           : No active profile set, falling back to default profiles: default
2021-06-29 12:18:11.149  INFO 69 --- [           main] com.baizhi.EmsApplicationTests           : Started EmsApplicationTests in 418.516 seconds (JVM running for 494.655)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 514.628 s - in com.baizhi.EmsApplicationTests
2021-06-29 12:19:24.357  INFO 69 --- [ionShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-0} closing ...
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ ems ---
[INFO] Building jar: /build/target/ems-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.5.2:repackage (repackage) @ ems ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19:22 min
[INFO] Finished at: 2021-06-29T12:20:33Z
[INFO] ------------------------------------------------------------------------
Removing intermediate container d92bbcd7ab54
 ---> e19081a12cd6
Step 6/8 : FROM adoptopenjdk/openjdk8:alpine-jre
alpine-jre: Pulling from adoptopenjdk/openjdk8
540db60ca938: Pull complete 
9fc18144b37f: Pull complete 
cc610e703026: Pull complete 
Digest: sha256:4e7f3fc23cfd6e9751a1465fc4daa2073a3987c72b178ba467b41f3971751205
Status: Downloaded newer image for adoptopenjdk/openjdk8:alpine-jre
 ---> 32011de768b3
Step 7/8 : COPY --from=builder /build/target/ems-0.0.1-SNAPSHOT.jar /ems.jar
 --->32011de768b3
Step 8/8 : CMD ["java", "-jar", "/ems.jar"]
 ---> Running in cc75371d3a8f
Removing intermediate container cc75371d3a8f
 ---> 32011de768b3
Successfully built 32011de768b3
Successfully tagged ems:1.0


最终效果:

[root@localhost ~/myems]# docker build -t ems:2.0 .  
Sending build context to Docker daemon  32.77kB
Step 1/8 : FROM maven:3.6.3-openjdk-8 AS builder
 ---> d1b3f61d61f2
Step 2/8 : RUN mkdir /build
 ---> Using cache
 ---> 836eeb13f7fe
Step 3/8 : ADD src /build/src
 ---> Using cache
 ---> b5d73ef7ed79
Step 4/8 : ADD pom.xml /build
 ---> Using cache
 ---> 5e9a5ce77859
Step 5/8 : RUN cd /build && mvn -B -ntp package
 ---> Using cache
 ---> e19081a12cd6
Step 6/8 : FROM adoptopenjdk/openjdk8:alpine-jre
 ---> 32011de768b3
Step 7/8 : COPY --from=builder /build/target/ems-0.0.1-SNAPSHOT.jar /ems.jar
 ---> 84666655f883
Step 8/8 : CMD ["java", "-jar", "/ems.jar"]
 ---> Running in cc75371d3a8f
Removing intermediate container cc75371d3a8f
 ---> 554142c1b512
Successfully built 554142c1b512
Successfully tagged ems:2.0


最终镜像制作成功

59.png


目录结构~

60.png


如果大家觉得还不错,点赞,收藏,分享,一键三连支持我一下~

相关实践学习
Docker镜像管理快速入门
本教程将介绍如何使用Docker构建镜像,并通过阿里云镜像服务分发到ECS服务器,运行该镜像。
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
目录
相关文章
|
10月前
|
Java Shell Maven
【Azure Container App】构建Java应用镜像时候遇无法编译错误:ERROR [build 10/10] RUN ./mvnw.cmd dependency:go-offline -B -Dproduction package
在部署Java应用到Azure Container App时,构建镜像过程中出现错误:“./mvnw.cmd: No such file or directory”。尽管项目根目录包含mvnw和mvnw.cmd文件,但依然报错。问题出现在Dockerfile构建阶段执行`./mvnw dependency:go-offline`命令时,系统提示找不到可执行文件。经过排查,确认是mvnw文件内容异常所致。最终通过重新生成mvnw文件解决该问题,镜像成功构建。
546 0
|
Java Linux
java基础(3)安装好JDK后使用javac.exe编译java文件、java.exe运行编译好的类
本文介绍了如何在安装JDK后使用`javac.exe`编译Java文件,以及使用`java.exe`运行编译好的类文件。涵盖了JDK的安装、环境变量配置、编写Java程序、使用命令行编译和运行程序的步骤,并提供了解决中文乱码的方法。
1049 2
|
Linux 网络安全 Docker
尼恩一键开发环境: vagrant+java+springcloud+redis+zookeeper镜像下载(&制作详解)
尼恩提供了一系列文章,旨在帮助开发者轻松搭建一键开发环境,涵盖Java分布式、高并发场景下的多种技术组件安装与配置。内容包括但不限于Windows和CentOS虚拟机的安装与排坑指南、MySQL、Kafka、Redis、Zookeeper等关键组件在Linux环境下的部署教程,并附带详细的视频指导。此外,还特别介绍了Vagrant这一虚拟环境部署工具,
尼恩一键开发环境: vagrant+java+springcloud+redis+zookeeper镜像下载(&制作详解)
|
分布式计算 大数据 Java
大数据-86 Spark 集群 WordCount 用 Scala & Java 调用Spark 编译并打包上传运行 梦开始的地方
大数据-86 Spark 集群 WordCount 用 Scala & Java 调用Spark 编译并打包上传运行 梦开始的地方
343 1
大数据-86 Spark 集群 WordCount 用 Scala & Java 调用Spark 编译并打包上传运行 梦开始的地方
|
数据采集 分布式计算 Java
Kettle的Java开发环境需要什么jar包?
【10月更文挑战第24天】Kettle的Java开发环境需要什么jar包?
547 2
|
存储 Java 开发者
成功优化!Java 基础 Docker 镜像从 674MB 缩减到 58MB 的经验分享
本文分享了如何通过 jlink 和 jdeps 工具将 Java 基础 Docker 镜像从 674MB 优化至 58MB 的经验。首先介绍了选择合适的基础镜像的重要性,然后详细讲解了使用 jlink 构建自定义 JRE 镜像的方法,并通过 jdeps 自动化模块依赖分析,最终实现了镜像的大幅缩减。此外,文章还提供了实用的 .dockerignore 文件技巧和选择安全、兼容的基础镜像的建议,帮助开发者提升镜像优化的效果。
|
IDE Java 编译器
Java:如何确定编译和运行时类路径是否一致
类路径(Classpath)是JVM用于查找类文件的路径列表,对编译和运行Java程序至关重要。编译时通过`javac -classpath`指定,运行时通过`java -classpath`指定。IDE如Eclipse和IntelliJ IDEA也提供界面管理类路径。确保编译和运行时类路径一致,特别是外部库和项目内部类的路径设置。
1008 5
|
存储 缓存 Java
Java应用瘦身记:Docker镜像从674MB优化至58MB的实践指南
【10月更文挑战第22天】 在容器化时代,Docker镜像的大小直接影响到应用的部署速度和运行效率。一个轻量级的Docker镜像可以减少存储成本、加快启动时间,并提高资源利用率。本文将分享如何将一个Java基础Docker镜像从674MB缩减到58MB的实践经验。
789 1
|
小程序 Oracle Java
JVM知识体系学习一:JVM了解基础、java编译后class文件的类结构详解,class分析工具 javap 和 jclasslib 的使用
这篇文章是关于JVM基础知识的介绍,包括JVM的跨平台和跨语言特性、Class文件格式的详细解析,以及如何使用javap和jclasslib工具来分析Class文件。
416 0
JVM知识体系学习一:JVM了解基础、java编译后class文件的类结构详解,class分析工具 javap 和 jclasslib 的使用
|
IDE Java 编译器
lombok编译遇到“找不到符号的问题”
【9月更文挑战第18天】当使用 Lombok 遇到 “找不到符号” 的问题时,可能是由于 Lombok 未正确安装、编译器不支持、IDE 配置不当或项目构建工具配置错误。解决方法包括确认 Lombok 安装、编译器支持,配置 IDE 和检查构建工具配置。通过这些步骤通常可解决问题,若问题仍存在,建议检查项目配置和依赖,或查看日志获取更多信息。
6615 2