Search code examples
javajbosswildflycachedrowset

Why NoClassDefFoundError for com/sun/rowset/CachedRowSetImpl in Wildfly?


My operating system is Windows 7 64-bit. I am working with Eclipse Luna. I am exploring migration from JBoss 4.2.3 to Wildfly 8.2.1.

I created a simple web app to test out com.sun.rowset.CachedRowSetImpl which I believe is part of JDK.

I created a class RowSetAdaptor as a wrapper for CachedRowSetImpl class:

package com.srh.util;

import java.io.Serializable;
import java.sql.SQLException;
import com.sun.rowset.CachedRowSetImpl;

public class RowSetAdaptor implements Serializable {
   private CachedRowSetImpl rowset;
   public RowSetAdaptor() {
      try {
         rowset = new CachedRowSetImpl();
      } catch (SQLException sqle) {
         System.out.println("RowSetAdaptor: constructor: SQLException=" + sqle);            
      }     
   }
}

Then I create a listener class AppContextListener:

package com.srh.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.srh.util.RowSetAdaptor;

public class AppContextListener implements ServletContextListener {
    public AppContextListener() {
    }

    public void contextInitialized(ServletContextEvent arg0) {
        RowSetAdaptor rsa = null;
        rsa = new RowSetAdaptor();
        System.out.println("AppContextListener: after create: rsa=" + rsa);
    }

    public void contextDestroyed(ServletContextEvent arg0) {
    }
}

Deploy the app to Jboss 4.2.3 and get the correct output in server.log:

AppContextListener: after create: rsa=com.srh.util.RowSetAdaptor@2a9073ef

Deploy the same app to Wildfly 8.2.1 and get a NoClassDefFoundError in server.log for CachedRowSetImpl :

Caused by: java.lang.NoClassDefFoundError: com/sun/rowset/CachedRowSetImpl

Since com.sun.rowset.CachedRowSetImpl is part of JDK so why is Wildfly giving this error? I am confused. How to resolve this issue?

Thanks


Solution

  • I followed these steps to resolve this issue:

    Open module.xml of JDK located in modules/system/layers/base/sun/jdk/main directory.

    Include these 3 lines under paths element:

    <path name="com/sun/rowset"/>
    <path name="com/sun/rowset/internal"/>
    <path name="com/sun/rowset/providers"/>
    

    Save module.xml

    Restart Wildfly

    Don't know why Wildfly JDK module does not come with these 3 lines already.