Uploaded image for project: 'Click'
  1. Click
  2. CLK-256

ClassNotFoundException in StandardClassLoader (Tomcat)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      1.4RC1
      Tomcat 5.0.16

      Description

      Problem with ClassNotFoundException for custom format class configured in click.xml (the same applies if a custom error page is configured for instance).
      This exception occurs for
      private void loadFormatClass(Element rootElm)
      ....
      formatClass = Class.forName(classname);
      .....

      To reproduce setup Tomcat directories like:

      • shared
      • - lib
        click-1.4RC1.jar
        click-extracts
      • webapps
          • myapp/WEB-INF/classes/com.mycorp.com/CustomFormat.class
            • myapp/WEB-INF/lib (empty)

      When I debugged this issue I found, that when the click servlet is inited Class.forName(classname) uses Tomcat's StandardClassLoader which searches for the class only in tomcat\shared\classes etc. but NOT in WEB-INF\classes.

      One workaround to solve this issue would be to copy the click....jar's to the WEB-INF/lib directory - yes then the problem does not occur, probably because the click servlet is loaded by the WebAppClassloader (sorry I had not time to investigate it further). However in our environment we store the libs in a shared location.

      The fix is to use the following code instead (this worked):
      ....
      // get the context classloader e.g. WebappClassLoader
      ClassLoader webCl = Thread.currentThread().getContextClassLoader();
      formatClass = Class.forName(classname, true, webCl);
      ....
      NOTE: There are 2 occurences of Class.loadClass in ClickApp to fix.

      Please review and fix this for the next release.

      Thx.

        Activity

        Hide
        medgar Malcolm Edgar added a comment -

        Fix checked into SVN, will be available in 1.4RC2.

        Note issues where observed loading message resources, using the Tomcat shared lib JAR deployment strategy.

        Show
        medgar Malcolm Edgar added a comment - Fix checked into SVN, will be available in 1.4RC2. Note issues where observed loading message resources, using the Tomcat shared lib JAR deployment strategy.

          People

          • Assignee:
            medgar Malcolm Edgar
            Reporter:
            harry.wissiak@audatex.ch harryw
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development