0

I have a Spring Boot application which runs locally in NetBeans and as a stand-alone jar (Win 10 Pro 1903 - 10.0.18362.239). However, when I attempt to run it in a docker container based on Windows nanoserver (same Windows version), the application crashes in the CommandLineRunner with a NoClassDefFoundError:

2019-08-03 18:12:57.232 ERROR ??? --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.NoClassDefFoundError: Could not initialize class java.net.InetAddress
        at org.springframework.boot.StartupInfoLogger.lambda$getOn$1(StartupInfoLogger.java:108) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getValue(StartupInfoLogger.java:138) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getValue(StartupInfoLogger.java:133) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getOn(StartupInfoLogger.java:108) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.getStartupMessage(StartupInfoLogger.java:68) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:50) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.logStartupInfo(SpringApplication.java:632) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:368) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at ai.com.neuralstudio.portal.server.ServerApplication.main(ServerApplication.java:117) [classes!/:0.0.4-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:86) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [server-0.0.4-SNAPSHOT.jar:0.0.4-SNAPSHOT]

I have run both (stand-alone and container) using the -verbose option, and it appears that in the stand-alone version some caching is occurring that does not occur in the container.

Stand-alone log - all instances of InetAddress in log (integers at end of lines are line number in log file):

[Loaded org.springframework.boot.convert.InetAddressFormatter from jar:file:/D:/Docker/portal-nanoserver-zulu/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-2.1.6.RELEASE.jar!/]
[Loaded java.net.InetAddress from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar] 1721
[Loaded java.net.InetAddress$1 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar] 2237

[Loaded java.net.InetAddress$InetAddressHolder from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$Cache from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$Cache$Type from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImplFactory from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.Inet6AddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImplFactory from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.Inet6AddressImpl from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$2 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy$1 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded sun.net.InetAddressCachePolicy$2 from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded java.net.InetAddress$CacheEntry from C:\Program Files\Zulu\zulu-8\jre\lib\rt.jar]
[Loaded com.fasterxml.jackson.databind.ser.std.InetAddressSerializer from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/jackson-databind-2.9.9.jar!/]

~2542 ASCII art and console starts (2542 is line in log file)

In container log, all instances of InetAddress:

[Loaded org.springframework.boot.convert.InetAddressFormatter from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-2.1.6.RELEASE.jar!/]
[Loaded java.net.InetAddress from c:\JDK_1.8-Zulu-222\jre\lib\rt.jar] 1711
[Loaded java.net.InetAddress$1 from c:\JDK_1.8-Zulu-222\jre\lib\rt.jar] 2278

[Loaded com.fasterxml.jackson.databind.ser.std.InetAddressSerializer from jar:file:/C:/portal/server-0.0.4-SNAPSHOT.jar!/BOOT-INF/lib/jackson-databind-2.9.9.jar!/]

~2674 ASCII art and console starts

java.lang.NoClassDefFoundError: Could not initialize class java.net.InetAddress 4143

Any suggestions for how to force the caching of InetAddress (if that is the problem) - or any other suggestions to fix it? Folks at OpenJDK have been less than helpful (no response in a week), and Spring Boot brushed it off as "we don't deal with runtime issues".

UPDATE 2019-09-02 Folks at Zulu (and others) have identified that there is a fundamental problem with apparently all JDKs after 1.8.0_181 or 192. There is more detailed information here: https://bugs.openjdk.java.net/browse/JDK-8225425

My own work-around was to revert to using the Zulu 192 JDK. I have not yet tried any later releases.

Thanks.

Jack Copper
  • 33
  • 1
  • 9
  • Can you edit your question and add the `Dockerfile`? – Ortomala Lokni Sep 01 '19 at 07:46
  • Can you make sure that you are using the same java version in docker. – Keaz Sep 29 '19 at 16:28
  • @Kaaz Yes, when the problem arose the JDK was the same in Docker and on local machine (where application was built). As I stated in the Update, I reverted to Zulu 192 and the container worked. At this point I have not retried later releases. – Jack Copper Sep 30 '19 at 17:11

0 Answers0