Spring boot application is not running on openWRT

308 Views Asked by At

I have tried to run a Spring boot microservice application on openWRT, but it causes a runtime exception which is java.lang.NoClassDefFoundError: java/nio/charset/StandardCharsets.

jvm used in openWRT is jamVM v2.0.0 and java v1.5.

The exception I am getting is

java.lang.reflect.InvocationTargetException
   at java.lang.reflect.VMMethod.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:327)
   at jamvm.java.lang.JarLauncher.main(JarLauncher.java:50)
Caused by: java.lang.NoClassDefFoundError: java/nio/charset/StandardCharsets
   at org.springframework.boot.loader.jar.AsciiBytes.<init>(AsciiBytes.java:51)
   at org.springframework.boot.loader.jar.JarFile.<clinit>(JarFile.java:59)
   at org.springframework.boot.loader.archive.JarFileArchive.<init>(JarFileArchive.java:61)
   at org.springframework.boot.loader.archive.JarFileArchive.<init>(JarFileArchive.java:57)
   at org.springframework.boot.loader.Launcher.createArchive(Launcher.java:127)
   at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:39)
   at org.springframework.boot.loader.JarLauncher.<init>(JarLauncher.java:36)
   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
   at java.lang.reflect.VMMethod.invoke(Native Method)
   ...2 more
Caused by: java.lang.ClassNotFoundException: java.nio.charset.StandardCharsets not found in java.lang.ClassLoader$1{urls=[file:/tmp/lan-socks-server-}
   at java.net.URLClassLoader.findClass(URLClassLoader.java:531)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:341)
   at java.lang.ClassLoader$1.loadClass(ClassLoader.java:1112)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:293)
   at org.springframework.boot.loader.jar.AsciiBytes.<init>(AsciiBytes.java:51) 

So the Spring boot is using a StandardCharsets class, that is released after v1.5.

My application build.gradle is

apply plugin: 'org.springframework.boot'

bootJar {
    baseName = 'lan-socks-server'
    version = "0.0.1"
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    implementation('io.netty:netty-all:4.1.42.Final')
    implementation('com.google.code.gson:gson:2.8.5')
}

So is there any other jvm support java 1.8 or how to rectify the issue?

Do I need to right the entire login in core java?

1

There are 1 best solutions below

0
On

I doubt it will work. I'm not familiar with openWRT, however note that:

  1. Spring boot 2.x relies on Spring 5 and therefor requires java 8 at least.
  2. Spring boot 1.4.x can run on java 7 and sometimes even on java 6 with additional configurations but java 5 is way too old.
  3. Side note, if you're planning to use spring boot 2.x it already supports netty by running webflux component for reactive systems (instead of using spring-boot-starter-web you can use spring-boot-starter-webflux), it will bring netty, no need to specify it explicitly.