Tuesday, January 29, 2013

java.lang.NoClassDefFoundError: sun/io/CharacterEncoding

sun.io.CharacterEncoding will be removed in JDK 8.  In our Java test using JDK 8, we have found the following message:
  • java.lang.NoClassDefFoundError: sun/io/CharacterEncoding
when WebLogic Server (WLS) started.

In this article, we will discuss how to trouble shoot and resolve this issue.

JVM Option -verbose


When it comes to java.lang.NoClassDefFoundError exception, one thing we need to find out this who has thrown that exception.  To trouble shoot class loading issues, the following JVM option comes in handy:
  • -verbose
After we add -verbose option, we have found the following messages from the WLS output:

[Loaded oracle.webservices.annotations.PortableWebService from file:/scratch/perfgrp/mt/rup1/fusionapps/oracle_common/modules/oracle.webservices_11.1.1/wsclient-rt.jar]
[Loaded oracle.j2ee.ws.common.util.TestPageUtils from file:/scratch/perfgrp/mt/rup1/fusionapps/oracle_common/modules/oracle.webservices_11.1.1/wsclient-rt.jar]


[Loaded java.lang.UnsatisfiedLinkError from /scratch/perfgrp/JVMs/jdk1.8.0/jre/lib/rt.jar]
[Loaded java.lang.VerifyError from /scratch/perfgrp/JVMs/jdk1.8.0/jre/lib/rt.jar]
[Loaded com.bea.logging.ThrowableWrapper from file:/scratch/perfgrp/mt/rup1/fusionapps/modules/com.bea.core.logging_1.9.0.0.jar]

java.lang.NoClassDefFoundError: sun/io/CharacterEncoding
        at oracle.j2ee.ws.common.util.TestPageUtils.encode(TestPageUtils.java:216)
        at oracle.j2ee.ws.server.management.mbeans.WebServiceOperation.createTestPagePath(WebServiceOperation.java:276)
        at oracle.j2ee.ws.server.management.mbeans.WebServiceOperation.initialize(WebServiceOperation.java:253)
        at oracle.j2ee.ws.server.management.mbeans.WebServiceOperation.(WebServiceOperation.java:244)
        at oracle.j2ee.ws.server.provider.GenericProviderInterceptorPipeline.registerWebServiceOperationMBean(GenericProviderInterceptorPipeline.java:175)
        Truncated. see log file for complete stack trace

After some investigation, we finally identify that TestPageUtils class from wsclient-rt.jar is the culprit. In JDK 8, the following class:
  • sun.io.CharacterEncoding 
will be removed.  It should be rewritten using:
  • java.nio.charset.Charset.forName()
For example, here are our changes:
//String encoding = sun.io.CharacterEncoding.aliasName(givenEncoding.toUpperCase());
String encoding = java.nio.charset.Charset.forName(givenEncoding.toUpperCase()).name();

How to Patch wsclient-rt.jar with New Class?


After we got a fix for TestPageUtils class, we loaded the jar with new class.  Note that from the -verbose output, we also know where TestPageUtils was loaded from.  For instance, it was loaded from:

  • /.../oracle_common/modules/oracle.webservices_11.1.1/wsclient-rt.jar

Here are the steps that we have taken to apply the patch:
  1. cd /.../oracle_common/modules/oracle.webservices_11.1.1
  2. mkdir tmpdir
  3. cd tmpdir
  4. cp ../wsclient-rt.jar .
  5. unzip wsclient-rt.jar
  6. cp <location of new patch>/TestPageUtils.class oracle/j2ee/ws/common/util
  7. jar uf /.../oracle_common/modules/oracle.webservices_11.1.1/wsclient-rt.jar oracle/j2ee/ws/common/util/TestPageUtils.class
  8. cd ..
  9. rm -rf tmpdir

References

3 comments:

Unknown said...

This worked great,

In addition, a similar patch must be done for

/.../oracle_common/modules/oracle.jsp_11.1.1/ojsp.jar, within oracle/jsp/util/JspUtil.class

Nitish Borade said...
This comment has been removed by the author.
Nitish Borade said...

I have installed OBIEE (v. 11.1.1.9.0) on Weblogic 10.3.6., extending an existing domain. My requirement is to use JDK 8. When I start up the servers, the following error is encountered and BI fails to start. The error is while loading wsclient-rt.jar java.lang.NoClassDefFoundError: sun/io/CharacterEncoding at oracle.j2ee.ws.common.util.TestPageUtils.encode(TestPageUtils.java:216)

After a research figured out that sun.io,CharacterEncoding is removed from JDK 8. I am aware that JDK 8 is not supported on Weblogic 10.3.6. But, is there any way I could get the BI publisher running on Weblogic 10.3.6 using JDK 8 or is there any patch available for weblogic 10.3.6. supporting JDK 8?