java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass

Upgrading from JDK8 to 17+ caused jaxb to run into this errors at run time. Solution remove older Jaxb jars and replace with newer jars that still provide “xml.bind”. When replacing try with 2.3.X jar versions as they still maintain the old sun class path, 3.XX jars have switched to the jarkarta class path which will mean updating some of your project imports and dependencies.

Remove any of the below libs

implementation group:'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
implementation group:'com.sun.xml.bind',name:'jaxb-impl', version: '2.3.0'
implementation group:'com.sun.xml.bind',name:'jaxb-core', version: '2.3.0'
    

replace with

implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '2.3.3'
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'

Leave a Reply

Your email address will not be published. Required fields are marked *