本文主要研究怎麼在docker的java9鏡像上運行springboot2並精簡jdk.html
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RC2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>9</java.version> <start-class>com.example.demo.DemoApplication</start-class> </properties>
注意springboot得2版本才能支持java9,另外這個java.version設置爲9
這裏maven用的版本是3.3.3
mvn clean package -Dmaven.test.skip=true //...... WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by lombok.javac.apt.LombokProcessor to field com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs WARNING: Please consider reporting this to the maintainers of lombok.javac.apt.LombokProcessor WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
能夠看到這裏能夠編譯成功,可是有WARNING
FROM dekstroza/openjdk9-alpine as packager # First stage: JDK 9 with modules required for Spring Boot RUN /opt/jdk-9/bin/jlink \ --module-path /opt/jdk-9/jmods \ --verbose \ --add-modules java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.desktop,java.management,java.naming,java.instrument \ --compress 2 \ --no-header-files \ --output /opt/jdk-9-minimal # Second stage, add only our custom jdk9 distro and our app FROM alpine:3.6 COPY --from=packager /opt/jdk-9-minimal /opt/jdk-9-minimal ENV JAVA_HOME=/opt/jdk-9-minimal ENV PATH="$PATH:$JAVA_HOME/bin" ## copy app.jar VOLUME /tmp ADD app.jar /app.jar #RUN sh -c 'touch /app.jar' EXPOSE 8080 ENTRYPOINT java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=${PROFILE} -jar /app.jar
這裏使用的是alpine鏡像,應爲它比較小,基礎鏡像就幾M,相比ubuntu等要小不少。因爲Alpine Linux使用MUSL做爲標準C庫,而openjdk依賴於GNU標準C庫(gclib),所以須要alpine版的jdk9才能夠在alpine上運行,可是目前jdk 9尚未正式的alpine鏡像,只有有一個early access的版 Announcing: Early-Access builds of JDK 9 for Alpine Linux/musl這裏咱們使用dekstroza基於alpine3.6構建好的鏡像dekstroza/openjdk9-alpine做爲jlink的基礎鏡像,而後肯定好工程依賴的jmods(
下面的內容會講怎麼肯定
),而後使用jlink構建最小的jdk運行環境.java這裏的--module-path(
-p
)指定依賴的模塊路徑;--add-modules添加root module用於分析依賴;--compress指定壓縮方式,0爲不壓縮,1爲常量字符串共享,2爲zip壓縮;--no-header-files指定排除頭文件;--verbose用於開啓trace輸出。react
mvn clean package -Dmaven.test.skip=true cd target cp ../src/main/docker/Dockerfile . docker build -t springboot2-java9-demo . docker run --rm -p 8080:8080 \ --name springboot2-java9-demo \ -e PROFILE=default \ springboot2-java9-demo
這個目前來講還沒找到現成命令/工具能夠動態找出工程依賴的jmod.不過能夠本身經過jdeps命令構建shell腳原本實現
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin>
這裏經過copy-dependencies插件把依賴jar存放到classes/lib目錄下,而後使用jdeps指定這個class-path來分析app.jar(
這樣作的目的主要是springboot打包出來的是fatjar,相關jar都在fatjar中,很差指定class-path
)
➜ target git:(master) ✗ jdeps --class-path 'classes/lib/*' -recursive -summary app.jar 拆分程序包: javax.annotation [jrt:/java.xml.ws.annotation, classes/lib/javax.annotation-api-1.3.1.jar, classes/lib/jsr305-1.3.9.jar] app.jar -> classes/lib/commons-lang3-3.7.jar app.jar -> classes/lib/guava-24.0-jre.jar app.jar -> java.base app.jar -> java.logging app.jar -> classes/lib/reactive-streams-1.0.2.jar app.jar -> classes/lib/reactor-core-3.1.4.RELEASE.jar app.jar -> classes/lib/rest-common-0.0.2.jar app.jar -> classes/lib/slf4j-api-1.7.25.jar app.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar app.jar -> classes/lib/spring-boot-2.0.0.RC2.jar app.jar -> classes/lib/spring-boot-autoconfigure-2.0.0.RC2.jar app.jar -> classes/lib/spring-context-5.0.4.RELEASE.jar app.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar app.jar -> classes/lib/spring-web-5.0.4.RELEASE.jar app.jar -> classes/lib/spring-webflux-5.0.4.RELEASE.jar checker-compat-qual-2.0.0.jar -> java.base commons-lang3-3.7.jar -> java.base error_prone_annotations-2.1.3.jar -> java.base guava-24.0-jre.jar -> classes/lib/checker-compat-qual-2.0.0.jar guava-24.0-jre.jar -> classes/lib/error_prone_annotations-2.1.3.jar guava-24.0-jre.jar -> java.base guava-24.0-jre.jar -> java.logging logback-classic-1.2.3.jar -> java.base logback-classic-1.2.3.jar -> java.management logback-classic-1.2.3.jar -> java.naming logback-classic-1.2.3.jar -> java.xml logback-classic-1.2.3.jar -> jdk.unsupported logback-classic-1.2.3.jar -> classes/lib/logback-core-1.2.3.jar logback-classic-1.2.3.jar -> classes/lib/slf4j-api-1.7.25.jar logback-classic-1.2.3.jar -> 找不到 logback-core-1.2.3.jar -> java.base logback-core-1.2.3.jar -> java.xml logback-core-1.2.3.jar -> 找不到 netty-buffer-4.1.21.Final.jar -> java.base netty-buffer-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-codec-4.1.21.Final.jar -> java.base netty-codec-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-codec-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-codec-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-codec-4.1.21.Final.jar -> 找不到 netty-codec-http-4.1.21.Final.jar -> java.base netty-codec-http-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-codec-http-4.1.21.Final.jar -> classes/lib/netty-codec-4.1.21.Final.jar netty-codec-http-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-codec-http-4.1.21.Final.jar -> classes/lib/netty-handler-4.1.21.Final.jar netty-codec-http-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-codec-socks-4.1.21.Final.jar -> java.base netty-codec-socks-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-codec-socks-4.1.21.Final.jar -> classes/lib/netty-codec-4.1.21.Final.jar netty-codec-socks-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-codec-socks-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-common-4.1.21.Final.jar -> java.base netty-common-4.1.21.Final.jar -> java.logging netty-common-4.1.21.Final.jar -> jdk.unsupported netty-common-4.1.21.Final.jar -> classes/lib/slf4j-api-1.7.25.jar netty-common-4.1.21.Final.jar -> 找不到 netty-handler-4.1.21.Final.jar -> java.base netty-handler-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-handler-4.1.21.Final.jar -> classes/lib/netty-codec-4.1.21.Final.jar netty-handler-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-handler-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-handler-4.1.21.Final.jar -> 找不到 netty-handler-proxy-4.1.21.Final.jar -> java.base netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-codec-4.1.21.Final.jar netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-codec-http-4.1.21.Final.jar netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-codec-socks-4.1.21.Final.jar netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-handler-proxy-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-resolver-4.1.21.Final.jar -> java.base netty-resolver-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-transport-4.1.21.Final.jar -> java.base netty-transport-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-transport-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-transport-4.1.21.Final.jar -> classes/lib/netty-resolver-4.1.21.Final.jar netty-transport-native-epoll-4.1.21.Final.jar -> java.base netty-transport-native-epoll-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-transport-native-epoll-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-transport-native-epoll-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar netty-transport-native-epoll-4.1.21.Final.jar -> classes/lib/netty-transport-native-unix-common-4.1.21.Final.jar netty-transport-native-unix-common-4.1.21.Final.jar -> java.base netty-transport-native-unix-common-4.1.21.Final.jar -> classes/lib/netty-buffer-4.1.21.Final.jar netty-transport-native-unix-common-4.1.21.Final.jar -> classes/lib/netty-common-4.1.21.Final.jar netty-transport-native-unix-common-4.1.21.Final.jar -> classes/lib/netty-transport-4.1.21.Final.jar reactive-streams-1.0.2.jar -> java.base reactor-core-3.1.4.RELEASE.jar -> java.base reactor-core-3.1.4.RELEASE.jar -> java.logging reactor-core-3.1.4.RELEASE.jar -> classes/lib/reactive-streams-1.0.2.jar reactor-core-3.1.4.RELEASE.jar -> classes/lib/slf4j-api-1.7.25.jar reactor-core-3.1.4.RELEASE.jar -> 找不到 reactor-netty-0.7.4.RELEASE.jar -> java.base reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-buffer-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-codec-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-codec-http-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-common-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-handler-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-handler-proxy-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-resolver-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-transport-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/netty-transport-native-epoll-4.1.21.Final.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/reactive-streams-1.0.2.jar reactor-netty-0.7.4.RELEASE.jar -> classes/lib/reactor-core-3.1.4.RELEASE.jar reactor-netty-0.7.4.RELEASE.jar -> 找不到 rest-common-0.0.2.jar -> java.base slf4j-api-1.7.25.jar -> java.base slf4j-api-1.7.25.jar -> classes/lib/logback-classic-1.2.3.jar spring-aop-5.0.4.RELEASE.jar -> java.base spring-aop-5.0.4.RELEASE.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar spring-aop-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-aop-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-beans-5.0.4.RELEASE.jar -> java.base spring-beans-5.0.4.RELEASE.jar -> java.desktop spring-beans-5.0.4.RELEASE.jar -> java.xml spring-beans-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-beans-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-beans-5.0.4.RELEASE.jar -> 找不到 spring-boot-2.0.0.RC2.jar -> java.base spring-boot-2.0.0.RC2.jar -> java.desktop spring-boot-2.0.0.RC2.jar -> java.management spring-boot-2.0.0.RC2.jar -> java.xml spring-boot-2.0.0.RC2.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar spring-boot-2.0.0.RC2.jar -> classes/lib/spring-context-5.0.4.RELEASE.jar spring-boot-2.0.0.RC2.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-boot-2.0.0.RC2.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-boot-2.0.0.RC2.jar -> classes/lib/spring-web-5.0.4.RELEASE.jar spring-boot-2.0.0.RC2.jar -> 找不到 spring-boot-autoconfigure-2.0.0.RC2.jar -> java.base spring-boot-autoconfigure-2.0.0.RC2.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar spring-boot-autoconfigure-2.0.0.RC2.jar -> classes/lib/spring-boot-2.0.0.RC2.jar spring-boot-autoconfigure-2.0.0.RC2.jar -> classes/lib/spring-context-5.0.4.RELEASE.jar spring-boot-autoconfigure-2.0.0.RC2.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-boot-autoconfigure-2.0.0.RC2.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> java.base spring-context-5.0.4.RELEASE.jar -> java.desktop spring-context-5.0.4.RELEASE.jar -> java.instrument spring-context-5.0.4.RELEASE.jar -> java.management spring-context-5.0.4.RELEASE.jar -> java.naming spring-context-5.0.4.RELEASE.jar -> java.xml spring-context-5.0.4.RELEASE.jar -> java.xml.ws spring-context-5.0.4.RELEASE.jar -> java.xml.ws.annotation spring-context-5.0.4.RELEASE.jar -> classes/lib/spring-aop-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> classes/lib/spring-expression-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-context-5.0.4.RELEASE.jar -> 找不到 spring-core-5.0.4.RELEASE.jar -> java.base spring-core-5.0.4.RELEASE.jar -> java.desktop spring-core-5.0.4.RELEASE.jar -> java.sql spring-core-5.0.4.RELEASE.jar -> java.xml spring-core-5.0.4.RELEASE.jar -> jdk.unsupported spring-core-5.0.4.RELEASE.jar -> classes/lib/netty-buffer-4.1.21.Final.jar spring-core-5.0.4.RELEASE.jar -> classes/lib/netty-common-4.1.21.Final.jar spring-core-5.0.4.RELEASE.jar -> classes/lib/reactive-streams-1.0.2.jar spring-core-5.0.4.RELEASE.jar -> classes/lib/reactor-core-3.1.4.RELEASE.jar spring-core-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-core-5.0.4.RELEASE.jar -> 找不到 spring-expression-5.0.4.RELEASE.jar -> java.base spring-expression-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-expression-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-jcl-5.0.4.RELEASE.jar -> java.base spring-jcl-5.0.4.RELEASE.jar -> java.logging spring-jcl-5.0.4.RELEASE.jar -> classes/lib/slf4j-api-1.7.25.jar spring-jcl-5.0.4.RELEASE.jar -> 找不到 spring-web-5.0.4.RELEASE.jar -> java.base spring-web-5.0.4.RELEASE.jar -> classes/lib/netty-buffer-4.1.21.Final.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/netty-codec-http-4.1.21.Final.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/netty-transport-4.1.21.Final.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/reactive-streams-1.0.2.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/reactor-core-3.1.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/reactor-netty-0.7.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/spring-beans-5.0.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/spring-context-5.0.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-web-5.0.4.RELEASE.jar -> 找不到 spring-webflux-5.0.4.RELEASE.jar -> java.base spring-webflux-5.0.4.RELEASE.jar -> classes/lib/reactive-streams-1.0.2.jar spring-webflux-5.0.4.RELEASE.jar -> classes/lib/reactor-core-3.1.4.RELEASE.jar spring-webflux-5.0.4.RELEASE.jar -> classes/lib/spring-context-5.0.4.RELEASE.jar spring-webflux-5.0.4.RELEASE.jar -> classes/lib/spring-core-5.0.4.RELEASE.jar spring-webflux-5.0.4.RELEASE.jar -> classes/lib/spring-jcl-5.0.4.RELEASE.jar spring-webflux-5.0.4.RELEASE.jar -> classes/lib/spring-web-5.0.4.RELEASE.jar
因爲classes/lib/log4j-api-2.10.0.jar是multi-release的需特殊指定multi-release 9,可是因爲使用的是recursive,所以這裏先臨時刪掉,再分析
經過輸出找出java,jdk開頭的,去重以後獲得所需的jmods
java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.desktop,java.management,java.naming,java.instrument
➜ target git:(master) ✗ jdeps --class-path 'classes/lib/*' -recursive --jdk-internals app.jar 拆分程序包: javax.annotation [jrt:/java.xml.ws.annotation, classes/lib/javax.annotation-api-1.3.1.jar, classes/lib/jsr305-1.3.9.jar] fastjson-1.2.35.jar -> java.base com.alibaba.fastjson.serializer.AnnotationSerializer -> sun.reflect.annotation.AnnotationType JDK internal API (java.base) guava-24.0-jre.jar -> jdk.unsupported com.google.common.cache.Striped64 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.cache.Striped64$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.cache.Striped64$Cell -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.LittleEndianByteArray$UnsafeByteArray -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.LittleEndianByteArray$UnsafeByteArray$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.LittleEndianByteArray$UnsafeByteArray$2 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.LittleEndianByteArray$UnsafeByteArray$3 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.Striped64 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.Striped64$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.hash.Striped64$Cell -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.primitives.UnsignedBytes$LexicographicalComparatorHolder$UnsafeComparator$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper -> sun.misc.Unsafe JDK internal API (jdk.unsupported) com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) logback-classic-1.2.3.jar -> jdk.unsupported ch.qos.logback.classic.spi.PackagingDataCalculator -> sun.reflect.Reflection JDK internal API (jdk.unsupported) lombok-1.16.20.jar -> jdk.compiler lombok.javac.apt.Processor -> com.sun.tools.javac.processing.JavacFiler JDK internal API (jdk.compiler) lombok.javac.apt.Processor -> com.sun.tools.javac.processing.JavacProcessingEnvironment JDK internal API (jdk.compiler) lombok.javac.apt.Processor -> com.sun.tools.javac.util.Context JDK internal API (jdk.compiler) lombok.javac.apt.Processor -> com.sun.tools.javac.util.Options JDK internal API (jdk.compiler) netty-common-4.1.21.Final.jar -> jdk.unsupported io.netty.util.internal.CleanerJava9 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.PlatformDependent$Mpsc$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.PlatformDependent0 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.PlatformDependent0$1 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.PlatformDependent0$2 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.PlatformDependent0$3 -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueConsumerNodeRef -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueueProducerNodeRef -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.LinkedQueueNode -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess -> sun.misc.Unsafe JDK internal API (jdk.unsupported) io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess -> sun.misc.Unsafe JDK internal API (jdk.unsupported) netty-handler-4.1.21.Final.jar -> java.base io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.util.ObjectIdentifier JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.AlgorithmId JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateAlgorithmId JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateIssuerName JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateSerialNumber JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateSubjectName JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateValidity JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateVersion JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.CertificateX509Key JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.X500Name JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.X509CertImpl JDK internal API (java.base) io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator -> sun.security.x509.X509CertInfo JDK internal API (java.base) objenesis-2.6.jar -> jdk.unsupported org.objenesis.instantiator.sun.UnsafeFactoryInstantiator -> sun.misc.Unsafe JDK internal API (jdk.unsupported) org.objenesis.instantiator.util.ClassDefinitionUtils -> sun.misc.Unsafe JDK internal API (jdk.unsupported) org.objenesis.instantiator.util.UnsafeUtils -> sun.misc.Unsafe JDK internal API (jdk.unsupported) reactor-core-3.1.4.RELEASE.jar -> jdk.unsupported reactor.core.publisher.MultiProducerRingBuffer -> sun.misc.Unsafe JDK internal API (jdk.unsupported) reactor.core.publisher.RingBuffer -> sun.misc.Unsafe JDK internal API (jdk.unsupported) reactor.core.publisher.RingBufferFields -> sun.misc.Unsafe JDK internal API (jdk.unsupported) reactor.core.publisher.UnsafeSequence -> sun.misc.Unsafe JDK internal API (jdk.unsupported) reactor.core.publisher.UnsafeSupport -> sun.misc.Unsafe JDK internal API (jdk.unsupported) spring-core-5.0.4.RELEASE.jar -> jdk.unsupported org.springframework.objenesis.instantiator.sun.UnsafeFactoryInstantiator -> sun.misc.Unsafe JDK internal API (jdk.unsupported) org.springframework.objenesis.instantiator.util.ClassDefinitionUtils -> sun.misc.Unsafe JDK internal API (jdk.unsupported) org.springframework.objenesis.instantiator.util.UnsafeUtils -> sun.misc.Unsafe JDK internal API (jdk.unsupported) 警告: 不支持 JDK 內部 API, 它們專用於經過不兼容方式來 刪除或更改的 JDK 實現, 可能會損壞您的應用程序。 請修改您的代碼, 消除與任何 JDK 內部 API 的相關性。 有關 JDK 內部 API 替換的最新更新, 請查看: https://wiki.openjdk.java.net/display/JDK8/Java+Dependency+Analysis+Tool JDK 內部 API 建議的替換 ---------- ----- com.sun.tools.javac.processing.JavacFiler Use javax.tools and javax.lang.model @since 1.6 com.sun.tools.javac.processing.JavacProcessingEnvironment Use javax.tools and javax.lang.model @since 1.6 com.sun.tools.javac.util.Context Use javax.tools and javax.lang.model @since 1.6 com.sun.tools.javac.util.Options Use javax.tools and javax.lang.model @since 1.6 sun.misc.Unsafe See http://openjdk.java.net/jeps/260 sun.reflect.Reflection Use java.lang.StackWalker @since 9 sun.reflect.annotation.AnnotationType Removed. See http://openjdk.java.net/jeps/260 sun.security.x509.X500Name Use javax.security.auth.x500.X500Principal @since 1.4
能夠發現netty,netty等還使用了sun.misc.Unsafe,這個被歸到了jdk.unsupported,顧名思義就是不建議用戶程序調用,它本來只想讓oracle jdk team來使用.
一個jdk8的鏡像,使用ubuntu可能要用到六七百M,使用alpine的話要大概200M.經過jlink以後這個例子的java9大小爲63.22M,加上springboot2的fatjar一共87.54M.git
目前本文所用的方式還有諸多不足,主要有以下幾點:web
jdk9的周邊設施還有待進一步完善